Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将数据帧转换为csv引号_Python_Csv_Pandas_Data Processing - Fatal编程技术网

Python 将数据帧转换为csv引号

Python 将数据帧转换为csv引号,python,csv,pandas,data-processing,Python,Csv,Pandas,Data Processing,我尝试使用 dataframe.to_csv('final_processed.csv', encoding='utf-8', index=False) 然后我得到了csv文件,它有5列,第一列是文本,我打开csv文件,发现有些行以引号开头和结尾,而其他行则没有(如下所示)。我希望它们都以引号开头和结尾,我该怎么办?非常感谢 “Pt因胸痛来到急诊室……Pt/INR和PTT在0324检查, PT/INR as 92.5/8.8和PTT wa 249.“,管理/监督,不开处方/命令,管理/监督,不

我尝试使用

dataframe.to_csv('final_processed.csv', encoding='utf-8', index=False)
然后我得到了csv文件,它有5列,第一列是文本,我打开csv文件,发现有些行以引号开头和结尾,而其他行则没有(如下所示)。我希望它们都以引号开头和结尾,我该怎么办?非常感谢

“Pt因胸痛来到急诊室……Pt/INR和PTT在0324检查, PT/INR as 92.5/8.8和PTT wa 249.“,管理/监督,不开处方/命令,管理/监督,不

“患者wa于2015年4月5日在办公室……这是一个意外发现 另一位护理者,向我的诊所报告 经理“,抄写/准备/分发,不开处方/命令,不管理/监督,不记录

多个药物由不同的提供者通过 不准确的剂量和……医院 入院,开处方/命令,开处方/命令,公证员/监督员,公证员


您需要将
quoting=True
添加到
dataframe.to_csv
中,如下所示:

dataframe.to_csv('final_processed.csv', encoding='utf-8', index=False, quoting=True)
您可以在官方文档中找到更多详细信息


下面是一个完全有效的示例

import pandas as pd 
from StringIO import StringIO 

st = """
"Pt come to ER with chest pain ..... PT/INR and PTT be check at 0324, PT/INR as 92 .5/8 .8 and PTT wa 249.",administer/monitor,notprescribe/order,administer/monitor,notadr

"Patient wa see in office on 05/04/2015 ....... Thi wa catch by another caregiver and report to my clinic manager.",transcribe/prepare/dispense,notprescribe/order,notadminister/monitor,notadr

Multiple medication enter on Med Rec by different provider with inaccurate dose and ......hospital admission,prescribe/order,prescribe/order,notadminister/monitor,notadr
"""
data =pd.read_csv(StringIO(st), delimiter=",", header=None) 
data.to_csv("final_processed.csv", encoding="utf-8", index=False, quoting=True)
输出如下所示:

 "0","1","2","3","4"
"Pt come to ER with chest pain ..... PT/INR and PTT be check at 0324, PT/INR as 92 .5/8 .8 and PTT wa 249.","administer/monitor","notprescribe/order","administer/monitor","notadr"
"Patient wa see in office on 05/04/2015 ....... Thi wa catch by another caregiver and report to my clinic manager.","transcribe/prepare/dispense","notprescribe/order","notadminister/monitor","notadr"
"Multiple medication enter on Med Rec by different provider with inaccurate dose and ......hospital admission","prescribe/order","prescribe/order","notadminister/monitor","notadr"

quoting=True:文件“pandas\core\generic.py”,第3020行,在to_csv:formatter.save()文件“pandas\io\formats\csvs.py”中,第170行,在保存:self.writer=UnicodeWriter(f,**writer\u kwargs)文件“pandas\io\common.py”,第545行,在UnicodeWriter中:返回csv.writer(f,方言=方言,**kwds)类型错误:“quoting”必须是整数ID您的意思是
双引号