如何在 pandas 中使用半冒号分隔符读取文件 [英] How to read a file with a semi colon separator in pandas
本文介绍了如何在 pandas 中使用半冒号分隔符读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用熊猫导入python中的.csv
文件.
I a importing a .csv
file in python with pandas.
这是.csv
中的文件格式:
a1;b1;c1;d1;e1;...
a2;b2;c2;d2;e2;...
.....
如何获取它:
from pandas import *
csv_path = "C:...."
data = read_csv(csv_path)
现在,当我打印文件时,我得到了:
Now when I print the file I get that :
0 a1;b1;c1;d1;e1;...
1 a2;b2;c2;d2;e2;...
以此类推...因此,我需要帮助来读取文件并将值拆分为半彩色字符;
.
And so on... So I need help to read the file and split the values in columns, with the semi color character ;
.
推荐答案
read_csv
采用sep
参数,在您的情况下,只需像这样传递sep=';'
即可:
read_csv
takes a sep
param, in your case just pass sep=';'
like so:
data = read_csv(csv_path, sep=';')
在您的情况下失败的原因是默认值为','
,因此它将所有列压缩为一个列条目.
The reason it failed in your case is that the default value is ','
so it scrunched up all the columns as a single column entry.
这篇关于如何在 pandas 中使用半冒号分隔符读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文