I want to convert a data frame so that each column becomes one list, named by the column name. To give an example, suppose I have the following data frame
import pandas as pd
d = {'A' : [1, 2, 3, 4],
'B' : ['x', 'y', 'z', 'w']}
df = pd.DataFrame(d)
print(df)
A B
0 1 x
1 2 y
2 3 z
3 4 w
The desired output is to have
A = [1,2,3,4]
B = ['x', 'y', 'z', 'w']
I know how to get the column names as well as the values into list format separately or together in the following ways:
test1 = df.T.reset_index().values.tolist()
print(test1)
[['A', 1, 2, 3, 4], ['B', 'x', 'y', 'z', 'w']]
test2 = df.T.values.tolist()
print(test2)
[[1, 2, 3, 4], ['x', 'y', 'z', 'w']]
test3 = df.columns.values.tolist()
print(test3)
['A', 'B']
But I cannot figure out if/how I can name the lists created in test2 the names as given by the column names.