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
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 would like to βpopulateβ the data frame so that each user an entry for all possible x with default padding y set to 0.
This is somewhat trivial in R (tidyverse / tidyr):
df %>% complete(nesting(user), x = c("a", "b", "c", "d"), fill = list(y = 0))
Is there an equivalent to complete in pandas / python that will give the same result?