Home > Mobile >  append a csv row at a list
append a csv row at a list

Time:12-02

I need to append a specific column of CSV file into a list.

I write the following code but the length of the list is 1!

It seems like it write all the rows as one element at the list.

true = []
X = pd.read_csv('DataSet.txt',encoding='utf-8',quotechar="'")
true.append(X['T'])

T: The name of the column at DataSet.txt file.

CodePudding user response:

Try this:

X = pd.read_csv('DataSet.txt',encoding='utf-8',quotechar="'")
true = X["T"].values.tolist()

Or, if you wanna append to an existing list:

true = []
X = pd.read_csv('DataSet.txt',encoding='utf-8',quotechar="'")
true.extend(X["T"].values.tolist())
  • Related