在 pandas 中使用 read_csv 时忽略双引号 (")
ignore a double quote (") while using read_csv in pandas
================================================== ====
Title: Whole case
Location: oyuri
From: Aki
Date: 2018/11/30 (Friday) 11:55:29
================================================== =====
1: Aki
2018/12/05 (Wed) 17:33:17
"
An approval notice has been sent.
-------------------------------------------------- ------------------
2: Aki
2018/12/06 (Thursday) 17:14:30
I was notified by Mr. Id, the agent of the other party.
-------------------------------------------------- ------------------
3: kano, etc.
2018/12/07 (Friday) 11:44:45
Please call rito.
-------------------------------------------------- ------------------
这是我已转换为 CSV 的文本文件
我面临的唯一问题是文件中有双引号 (")(例如,在此文件中的条目号 1 中)
读取 CSV 文件时如何忽略双引号?
我在读取文件时使用的分隔符是 \n
df = pd.read_csv(filename ,sep='\n', header=None)
尝试通过 quoting = csv.QUOTE_NONE
或(如果这不起作用)玩 quotechar
?
import csv
df = pd.read_csv(filename, sep='\n', header=None, quoting=csv.QUOTE_NONE)
这里是:
df = pd.read_csv('sample.csv' ,sep='\n', header=None, quotechar="'")
print(df)
#output:
0
0 ==============================================...
1 Title: Whole case
2 Location: oyuri
3 From: Aki
4 Date: 2018/11/30 (Friday) 11:55:29
5 ==============================================...
6 1: Aki
7 2018/12/05 (Wed) 17:33:17
8 "
9 An approval notice has been sent.
10 ----------------------------------------------...
11 2: Aki
12 2018/12/06 (Thursday) 17:14:30
13 I was notified by Mr. Id, the agent of the oth...
14 ----------------------------------------------...
15 3: kano, etc.
16 2018/12/07 (Friday) 11:44:45
17 Please call rito.
18 ----------------------------------------------...
在使用 read_csv
时忽略双引号 "
包括 quotechar='"'
pd.read_csv(PATH_TO_CSV, sep=',', engine='python', quotechar='"')
您还可以在此处查看其他选项:
https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html#
================================================== ====
Title: Whole case
Location: oyuri
From: Aki
Date: 2018/11/30 (Friday) 11:55:29
================================================== =====
1: Aki
2018/12/05 (Wed) 17:33:17
"
An approval notice has been sent.
-------------------------------------------------- ------------------
2: Aki
2018/12/06 (Thursday) 17:14:30
I was notified by Mr. Id, the agent of the other party.
-------------------------------------------------- ------------------
3: kano, etc.
2018/12/07 (Friday) 11:44:45
Please call rito.
-------------------------------------------------- ------------------
这是我已转换为 CSV 的文本文件 我面临的唯一问题是文件中有双引号 (")(例如,在此文件中的条目号 1 中) 读取 CSV 文件时如何忽略双引号? 我在读取文件时使用的分隔符是 \n
df = pd.read_csv(filename ,sep='\n', header=None)
尝试通过 quoting = csv.QUOTE_NONE
或(如果这不起作用)玩 quotechar
?
import csv
df = pd.read_csv(filename, sep='\n', header=None, quoting=csv.QUOTE_NONE)
这里是:
df = pd.read_csv('sample.csv' ,sep='\n', header=None, quotechar="'")
print(df)
#output:
0
0 ==============================================...
1 Title: Whole case
2 Location: oyuri
3 From: Aki
4 Date: 2018/11/30 (Friday) 11:55:29
5 ==============================================...
6 1: Aki
7 2018/12/05 (Wed) 17:33:17
8 "
9 An approval notice has been sent.
10 ----------------------------------------------...
11 2: Aki
12 2018/12/06 (Thursday) 17:14:30
13 I was notified by Mr. Id, the agent of the oth...
14 ----------------------------------------------...
15 3: kano, etc.
16 2018/12/07 (Friday) 11:44:45
17 Please call rito.
18 ----------------------------------------------...
在使用 read_csv
时忽略双引号 "
包括 quotechar='"'
pd.read_csv(PATH_TO_CSV, sep=',', engine='python', quotechar='"')
您还可以在此处查看其他选项:
https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html#