简体   繁体   English

pandas.read_csv没有以分号分隔符分区数据

[英]pandas.read_csv not partitioning data at semicolon delimiter

I'm having a tough time correctly loading csv file to pandas dataframe. 我正在艰难地将csv文件正确加载到pandas数据帧。 The file is csv saved in MS Excel, where the rows looks like this: 该文件是在MS Excel中保存的csv ,其行如下所示:

Montservis, s.r.o.;"2 012";"-14.98";"-34.68";"- 11.7";"0.02";"0.09";"0.16";"284.88";"10.32";"

I am using 我在用

filep="file_name.csv"
raw_data = pd.read_csv(filep,engine="python",index_col=False, header=None, delimiter=";")

(I have tried several combinations and alternatives of read_csv arguments, but without any success.....I have tried also read_table ) (我已经尝试了几种read_csv参数的组合和替代方案,但没有任何成功.....我也试过read_table)

What I want to see in my dataframe that each semi colon separated value will be in separate column (I understand that read_csv works this way(?)). 我希望在我的数据框中看到每个半冒号分隔值将在单独的列中(我知道read_csv这种方式工作(?))。

Unfortunately, I always end up with whole row being placed in first column of dataframe. 不幸的是,我总是将整行放在数据帧的第一列。 So basicly after loading I have many rows, but only one column (two if I count also indexes) 所以基本上加载后我有很多行,但只有一列(如果我也计算两个列,则为两列)

I have placed sample here: datafile 我在这里放置了样本: datafile

Any idea welcomed. 欢迎任何想法。

问题是包含\\字符可以忽略的字符。

raw_data = pd.read_csv(filep,engine="python",index_col=False, header=None, delimiter='\;')

Add quoting = 3 . 添加quoting = 3 3 is for QUOTE_NONE refer this . 3是QUOTE_NONE参考这个

   raw_data = pd.read_csv(filep,engine="python",index_col=False, header=None, delimiter=";", quoting = 3)

This will give [7 rows x 23 columns] dataframe 这将给出[7 rows x 23 columns]数据帧

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM