I have a dataframe as follows:
df=
year|text|value
2001|text1|10
2001|text2|11
2002|text2|12
2003|text3|56
2005|text8|8
2005|text1|23
Now,I want to make a list of lists from the dataframe as follows:
l1=[[[10,0,0,23],[0,12,0,0],[0,0,56,0],[0,0,0,8]],[text1,text2,text3,text8],[2001,2002,2003,2005]]
I want to add zeros in the list when there is no value for the text in a particular year.
I have tried the following code:
for value in list(df['text'].values):
df1=df[df['text']==value]
series_list.append(list(df1['value'].values))
names_list.append(value)
year_list.append(list(df1['year'].values))
I did not get the expected output. I initially tried to make 3 separate lists.