Home > Mobile >  Devide Pandas dataframe into list of rows containing all columns
Devide Pandas dataframe into list of rows containing all columns

Time:07-20

I need to devide Pandas dataframe into list of rows with all columns. That means that if there's a dataframe with n rows and m columns I need to make a list of n elements and each element should be 1 x m row.

CodePudding user response:

It looks like you want:

df.values.tolist()

example:

df = pd.DataFrame([['A', 'B', 'C'],
                   ['D', 'E', 'F']])

df.values.tolist()

output:

[['A', 'B', 'C'],
 ['D', 'E', 'F']]
  • Related