python怎么将csv文件中的列存入列表(python向csv文件中写入数据)
http://www.itjxue.com 2023-03-24 18:00 来源:未知 点击次数:
python 怎么把csv中的数据写入列表?
使用pandas读取的方法是
pandas.to_csv()
得到的结果是dataframe格式,再用numpy库转一下
具体代码:
import pandas as pd
import numpy as np
file_content = pd.to_csv(r'C:\新建文件夹\result123.csv')
row = np.array(file_content)
lx = row.tolist()

python读取csv文件中的多列数据为列表
import?csv
reader?=?csv.reader(file('name.csv',?'rb'))
for?line?in?reader:
????print?line
#这个reader?读出来就是一个列表
python如何读取csv某列XX行数据保存为列表?
list1 = df[[df.columns[2],df.columns[0]]]
list2 = df[[df.columns[2],df.columns[1]]]