简体   繁体   English

append 一个 csv 行在一个列表中

[英]append a csv row at a list

I need to append a specific column of CSV file into a list.我需要将 append 文件的特定列 CSV 放入一个列表。

I write the following code but the length of the list is 1!我写了下面的代码,但列表的长度是 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. T: DataSet.txt文件中列的名称。

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:或者,如果您想要 append 到现有列表:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM