Pandas.read_csv将所有文件读入一列 [英] Pandas.read_csv reads all of the file into one column
本文介绍了Pandas.read_csv将所有文件读入一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个格式为"...","...","..." ...的csv文件,其中包含40多个列.当我使用这个简单的代码时,它只会给我一个巨大的钥匙.我已经把它弄乱了一个多小时,我不知道如何用熊猫来解决这个问题.
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.
dataframe = pd.read_csv(filePath, header=0, encoding='iso-8859-1')
datakeys = dataframe.keys();
print(datakeys)
推荐答案
我通过指定 read_csv
的 names
字段和 header = None 来解决此问题.代码>.
I fixed the issue by specifying names
field of read_csv
and header=None
.
fields = ["colA", "colB"];
df = pd.read_csv("/tmp/data.csv", sep="|", header=None, names=fields)
这篇关于Pandas.read_csv将所有文件读入一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文