[英]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=";")
This data looks as:该数据如下所示:
one two three
1 2 3 NaN
4 5 6 NaN
The desired result is:期望的结果是:
one two three
1 2 3
4 5 6
I could manually edit the csv, but I don't really want to have to do that if possible.我可以手动编辑 csv,但如果可能的话,我真的不想这样做。
In R
the function read_delim
can manage this with something along the lines of read_delim( <path>, ";", escape_double = FALSE, trim_ws = TRUE)
在
R
中,function read_delim
可以通过read_delim( <path>, ";", escape_double = FALSE, trim_ws = TRUE)
For me working index_col=False
parameter:对我来说工作
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.