Home > Software engineering >  merge all columns in data frame to a list
merge all columns in data frame to a list

Time:10-09

So I have a csv file with no headers and want to take all the columns in the data frame and want to "append" all the columns into a list.

for example I have df:

1 2 7
3 4 8
5 6 9

I have a pseudocode on what I want to perform

import pandas as pd

df = pd.read_csv('file.csv',header=None)
data = []

for i in range(number of columns) #in this case we have 3
    data.append(df[i])

#data = [1,2,3,4,5,6,7,8,9]

CodePudding user response:

UUIC, you can try flatten then sort

import numpy as np

np.sort(df.values.flatten())

array([1, 2, 3, 4, 5, 6, 7, 8, 9])
  • Related