For a dictionary:
d = {
"a": [1],
"b": 2,
"c": [[7, 8, 9], ["a", "b", "c"], [9, 10, 11]],
"d": None,
}
I want to achieve this dataframe:
pd.DataFrame({"a": [[1], [1], [1]],
"b": [2, 2, 2],
"c": [[7, 8, 9], ["a", "b", "c"], [9, 10, 11]],
"d": [None, None, None]})
a b c d
0 [1] 2 [7, 8, 9] None
1 [1] 2 [a, b, c] None
2 [1] 2 [9, 10, 11] None
Basically, the columns should duplicate itself until the length of the longest column.
I know in R if i create a dataframe like with NA to indicate the rows i want to duplicate and use tidyr::fill, is there something similar in python?
df = data.frame(
a = c("a", NA, NA),
b = c(1, 2, 3)
)
tidyr::fill(df, a)
a b
1 a 1
2 a 2
3 a 3