使用Python中的列保存到csv

使用Python中的列保存到csv,python,csv,cluster-analysis,Python,Csv,Cluster Analysis,我需要您的帮助将我的群集从阵列保存到带有列的CSV文件 我对CSV的期望是这样的 text || label car || vehicle cup || stuff 这是我的密码 import csv row=[["TEXT","LABEL"], Corpus['text_final'],Corpus['tags']] with open('text_label.csv', 'w', newline='') as file: writer = csv.writer(fil

我需要您的帮助将我的群集从阵列保存到带有列的CSV文件

我对CSV的期望是这样的

text || label
car  || vehicle
cup  || stuff
这是我的密码

import csv
row=[["TEXT","LABEL"],
     Corpus['text_final'],Corpus['tags']]
with open('text_label.csv', 'w', newline='') as file:
    writer = csv.writer(file)
    writer.writerows(row)

这似乎与集群无关

看起来你这里有一张清单。首先将列表转换为数据帧

df = pd.DataFrame(lst)
然后,将DF导出为CSV。可以使用Python中的以下模板将数据帧导出到CSV文件:

df.to_csv(r'C:\\Your_Path_Here\\File_Name.csv', index = False)
如果您希望包含索引,则只需从代码中删除“、index=False”:

df.to_csv(r'C:\\Your_Path_Here\\File_Name.csv')