Python how to combine two columns of a dataframe into a single list?

Mainland :

I have a dataframe as given below

df = 

index    data1    data2
0         20       120
1         30       456
2         40       34

How to combine two columns in above df into a single list such that first row elements come first and then second row.

My expected output

my_list = [20,120,30,456,40,34]

My code:

list1 = df['data1'].tolist()
list2 = df['data2'].tolist()

my_list = list1+list2

This did not work?

U10-Forward :

That doesn't work since it won't add by same index, use the below list comprehension:

print([x for i in zip(df['data1'], df['data2']) for x in i])

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=11594&siteId=1