Python 如何在熊猫中读取带有分号分隔符的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24606330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 04:51:15  来源:igfitidea点击:

How to read a file with a semi colon separator in pandas

pythoncsvpandas

提问by Jean

I a importing a .csvfile in python with pandas.

.csv用pandas在python中导入一个文件。

Here is the file format from the .csv:

这是来自以下文件的文件格式.csv

a1;b1;c1;d1;e1;...
a2;b2;c2;d2;e2;...   
.....

here is how get it :

这里是如何得到它:

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 ;.

等等......所以我需要帮助来读取文件并使用半色字符将值拆分为列;

采纳答案by EdChum

read_csvtakes a sepparam, in your case just pass sep=';'like so:

read_csv需要一个sep参数,在你的情况下sep=';'就像这样传递:

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.

在您的情况下失败的原因是默认值是','将所有列作为单个列条目进行整理。