I have a pandas dataframe with the following form:
import pandas as pd
p = pd.DataFrame({"int" : [1, 1, 1, 1, 2, 2],
"cod" : [[1,1], [2,2], [1,2], [3,9], [2,2], [2,2]]})
I want to group by int
, which gives me a bunch of lists. I then want to flatten these lists, so I ultimately end up with a dataframe that has this form:
p = pd.DataFrame({"int" : [1, 2],
"cod" : [[1,1,2,2,1,2,3,9], [2,2,2,2]]})
Here is what I have so far:
p.groupby("int", as_index=False)["cod"]
I'm stuck at how to flatten once I have grouped by int