【发布时间】:2014-01-30 16:51:32
【问题描述】:
从 csv 中读取数据的最佳方式是什么,但只能读取一个特定的列,例如 title?
ID | date| title |
-------------------
1| 2013| abc |
2| 2012| cde |
然后该列应存储在这样的数组中:
data = ["abc", "cde"]
这是我目前所拥有的,pandas:
data = pd.read_csv("data.csv", index_col=2)
我已经调查过this thread。我仍然收到IndexError: list index out of range。
编辑:
这不是表格,它是这样用逗号分隔的:
ID,date,title
1,2013,abc
2,2012,cde
【问题讨论】:
-
这真的是你的文件的样子吗,
|和--等等? (不是真正的 CSV,逗号分隔值,但我们应该能够通过一些工作来读取它。) -
你确定 all 行有 3 列吗?听起来好像您的某些行缺少第三列,也许更多。