如何在 pandas 中读取带有分号分隔符的文件 [英] How to read a file with a semi colon separator in pandas
本文介绍了如何在 pandas 中读取带有分号分隔符的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用 Pandas 在 python 中导入一个 .csv
文件.
I a importing a .csv
file in python with pandas.
这是来自 .csv
的文件格式:
Here is the file format from the .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屋!
查看全文