I have a nested list in this format mydata=[[01/01/20,['point1','point2','point3,...]],[02/01/20,['point1','point2','point3']],...]
I want to create a pandas dataframe grouped by date with every point as a different row.
I have tried manually adding each row through a for loop, but other than taking more than an hour, the dataframe ended up being empty.
Not sure how to go about this. Can I create the grouped dataframe directly from the list?
My desired output would be:
JavaScript
x
9
1
date points
2
3
01/01/20 point1
4
point2
5
point3
6
02/01/20 point1
7
point2
8
point3
9
Advertisement
Answer
The expected output is not fully clear, but if I guess correctly:
JavaScript
1
5
1
mydata = [['01/01/20',['point1','point2','point3']],
2
['02/01/20',['point1','point2','point3']]]
3
4
df = pd.DataFrame(dict(mydata))
5
Or:
JavaScript
1
4
1
cols, data = zip(*mydata)
2
3
df = pd.DataFrame(zip(*data), columns=cols)
4
output:
JavaScript
1
5
1
01/01/20 02/01/20
2
0 point1 point1
3
1 point2 point2
4
2 point3 point3
5