我试图将信息列表写入python中的.csv文件。到目前为止,我只能打印标题。我想从现有的.csv文件中抓取2列,用我的数据写入新的.csv文件。到目前为止,我有如何在Python中将数据列表写入.csv文件?
def get_id_size():
read_file = pandas.read_csv('poem_info.csv')
poemid = (read_file[['poemname']])
poemsize = (read_file[['poemsize']])
return (poemid, poemsize) #this is the columns i want in my new.csv file
with open('poem_data.csv', 'w') as outfile:
# write header
outfile.write('poemid,poemsize,cli,ari\n')
我的新数据是
cli = calculate_cli
ari = calculate_ari
所以我的问题是:如何分配poemid,poemsize,CLI和ARI到CSV文件?我很新的蟒蛇,我不能找出语法这样做
你真的需要'pandas'?似乎你并没有像内置'csv'模块(特别是在Py3上,它对Unicode友好)无法处理的东西那样使用它。 – ShadowRanger
我并不特别需要它,但我认为这将是更快,如果我使用 – emptybladder
是'calculate_cli()大熊猫'并读入现有的CSV文件'calculate_ari()'使用'从和poemid''poemsize'值? – nbeuchat