pandas or python equivalent of tidyr complete
问题 I have data that looks like this: library("tidyverse") df <- tibble(user = c(1, 1, 2, 3, 3, 3), x = c("a", "b", "a", "a", "c", "d"), y = 1) df # user x y # 1 1 a 1 # 2 1 b 1 # 3 2 a 1 # 4 3 a 1 # 5 3 c 1 # 6 3 d 1 Python format: import pandas as pd df = pd.DataFrame({'user':[1, 1, 2, 3, 3, 3], 'x':['a', 'b', 'a', 'a', 'c', 'd'], 'y':1}) I'd like to "complete" the data frame so that every user has a record for every possible x with the default y fill set to 0. This is somewhat trivial in R