I have a dataframe (df) and I want to transform it to a nested list.
df=pd.DataFrame({'Number':[1,2,3,4,5, 6],
'Name':['A', 'B', 'C', 'D', 'E', 'F'],
'Value': [223, 124, 434, 514, 821, 110]})
My expected outcome is a nested list. The first list inside the nested takes values from the first 3 rows of df from the first column. The second then the first 3 rows of the second column and the third the 3 first rows of the third column. After that I want to add lists of the remaning 3 rows.
[[1, 2, 3],
['A', 'B', 'C'],
[223, 124, 434]
[4, 5, 6],
['D', 'E', 'F'],
[514, 821, 110]]
I did a for loop and called tolist() on each series. Then I get all the values from one column in a list. How do I go from the outcome below to the expected outcome above?
col=df.columns
lst=[]
for i in col:
temp = df[i].tolist()
temp
lst.append(temp)
Outcome (lst):
[[1, 2, 3, 4, 5, 6],
['A', 'B', 'C', 'D', 'E', 'F'],
[223, 124, 434, 514, 821, 110]]
df.iloc[:3,:].T.values.tolist() + df.iloc[3:,:].T.values.tolist()?