Pandas.read_csv 将所有文件读入一列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30925471/
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
Pandas.read_csv reads all of the file into one column
提问by Fonti
I have a csv file in the form "...","...","..."... with over 40 columns. When I used this simple code, it only gives me one massive key. I've been messing with it for over an hour and I can't figure how to use pandas to fix this.
我有一个格式为“...”、“...”、“...”的 csv 文件,有 40 多列。当我使用这个简单的代码时,它只给了我一个巨大的密钥。我已经弄了一个多小时了,我不知道如何使用Pandas来解决这个问题。
dataframe = pd.read_csv(filePath, header=0, encoding='iso-8859-1')
datakeys = dataframe.keys();
print(datakeys)
回答by RAJK
I fixed the issue by specifying namesfield of read_csvand header=None.
我通过指定andnames字段解决了这个问题。read_csvheader=None
fields = ["colA", "colB"];
df = pd.read_csv("/tmp/data.csv", sep="|", header=None, names=fields)
回答by Fonti
I fixed the issue by writing a script to reformat the .csv There was a minor formatting issue in the .csv that was causing Panda to basically do nothing. Weird
我通过编写脚本来重新格式化 .csv 解决了这个问题 .csv 中存在一个小格式问题,导致 Panda 基本上什么都不做。奇怪的

