无法在 Pandas 中导入逗号分隔的引用文件
Cannot import comma delimited quoted file in Pandas
我正在尝试将此数据导入 Pandas
。它使用 header 和 2 行在 Libreoffice 中正确导入。但是,在Pandas
,好像没有导入。里面有一些换行符应该被忽略。但是在 Pandas 中,它们被视为一个新行,而不是其中包含 \n
的单个字段。有没有人遇到过这样的问题。我尝试在 Pandas
中设置 quotechar
和 sep
参数,但无法导入它。
提前致谢
这应该作为 2 行导入 Pandas。但是,它被分成多行。
你的问题是你的文本中有 "
作为转义字符 (\"
),panda 应该忽略它。
例如
7/20/16: Decreased STS, active flexion to 130, abduction to 100, weak right handed grip. Lack 6-8 \" IR on right, only to waist.
Lack 6-8 后的 \" 不应被解释为引号字符。
你必须告诉 pandas。
应该可行:
import pandas as pd
df = pd.read_csv("resources/data_to_post.csv", quotechar='"', escapechar='\')
print(df)
输出
id ... PlanGenerated
0 1 ... A course of physical therapy was ordered. Mobi...
1 2 ... The patient is instructed to return if pain or...
[2 rows x 17 columns]
只有两行,然后像以前一样有 6 行。
我正在尝试将此数据导入 Pandas
。它使用 header 和 2 行在 Libreoffice 中正确导入。但是,在Pandas
,好像没有导入。里面有一些换行符应该被忽略。但是在 Pandas 中,它们被视为一个新行,而不是其中包含 \n
的单个字段。有没有人遇到过这样的问题。我尝试在 Pandas
中设置 quotechar
和 sep
参数,但无法导入它。
提前致谢
这应该作为 2 行导入 Pandas。但是,它被分成多行。
你的问题是你的文本中有 "
作为转义字符 (\"
),panda 应该忽略它。
例如
7/20/16: Decreased STS, active flexion to 130, abduction to 100, weak right handed grip. Lack 6-8 \" IR on right, only to waist.
Lack 6-8 后的 \" 不应被解释为引号字符。
你必须告诉 pandas。
应该可行:
import pandas as pd
df = pd.read_csv("resources/data_to_post.csv", quotechar='"', escapechar='\')
print(df)
输出
id ... PlanGenerated
0 1 ... A course of physical therapy was ordered. Mobi...
1 2 ... The patient is instructed to return if pain or...
[2 rows x 17 columns]
只有两行,然后像以前一样有 6 行。