python pandas不从csv文件读取第一列 [英] python pandas not reading first column from csv file
本文介绍了python pandas不从csv文件读取第一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为st1.csv的简单的2列csv文件:
GRID St1
$ p $但是,当我尝试读取csv文件时,不会加载第一列:
1457 614
1458 657
1459 679
1460 732
1461 754
1462 811
1463 748
code> a = pandas.DataFrame.from_csv('st1.csv')
a.columns
输出:
索引([u'ST1'],dtype = object )
为什么不读取第一列?
解决方案根据您的数据判断,您使用的分隔符看起来像是
。
请尝试以下操作:
a = pandas.DataFrame.from_csv ('st1.csv',sep ='')
另一个问题是, column是一个索引,我们也可以禁用:
a = pandas.DataFrame.from_csv('st1.csv',index_col = False)
I have a simple 2 column csv file called st1.csv:
GRID St1 1457 614 1458 657 1459 679 1460 732 1461 754 1462 811 1463 748
However, when I try to read the csv file, the first column is not loaded:
a = pandas.DataFrame.from_csv('st1.csv') a.columns
outputs:
Index([u'ST1'], dtype=object)
Why is the first column not being read?
解决方案Judging by your data it looks like the delimiter you're using is a
.
Try the following:
a = pandas.DataFrame.from_csv('st1.csv', sep=' ')
The other issue is that it's assuming your first column is an index, which we can also disable:
a = pandas.DataFrame.from_csv('st1.csv', index_col=False)
这篇关于python pandas不从csv文件读取第一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文