![](/img/trans.png)
[英]How to read a csv file with Pandas with more delimiters in the rows that in the header?
[英]How to read a csv in pandas with a missing delimiter (or - with additional delimiters)
import pandas as pd
from io import StringIO
csv_one = """\
one;two;three
1;2;3;
4;5;6;
"""
df1 = pd.read_csv(StringIO(csv), sep=";")
该数据如下所示:
one two three
1 2 3 NaN
4 5 6 NaN
期望的结果是:
one two three
1 2 3
4 5 6
我可以手动编辑 csv,但如果可能的话,我真的不想这样做。
在R
中,function read_delim
可以通过read_delim( <path>, ";", escape_double = FALSE, trim_ws = TRUE)
对我来说工作index_col=False
参数:
csv = """\
one;two;three
1;2;3;
4;5;6;
"""
df1 = pd.read_csv(StringIO(csv), sep=";", index_col=False)
print (df1)
one two three
0 1 2 3
1 4 5 6
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.