Python中CSV文件的三种保存方法

  1. pandas的to_csv方法
embeddings_df.to_csv("patients_note_embedding.csv", index=False)
#embeddings_df改成自己的数据名字
  1. np.savetxt方法
np.savetxt("patients_note_embedding.csv", embeddings_df.values, delimiter=",", fmt="%s")
  1. python内置的存储csv方法
import csv
with open('patients_note_embedding2.csv', 'w', newline='') as file:
    writer = csv.writer(file)
    writer.writerows(embeddings_df.values)
print("CSV文件保存成功!")

记得改文件名为你自己的文件名

作者:QQRRRRW

物联沃分享整理
物联沃-IOTWORD物联网 » Python中CSV文件的三种保存方法

发表回复