Pandas read_csv()没有给出列内容

时间:2017-06-07 06:53:07

标签: python-3.x csv pandas dataframe

我有一个带有#as delimiter的csv表。格式如下:

Date#body
10/16/2016 9:00 AM#" الأردنية" تحصد المراكز الثلاثة في مسابقة المحادثة...
....

当我用

读取文件时

table = pandas.read_csv('path/to/file/table.csv',delimiter='#',error_bad_lines=False)

我明白了:

print(table.columns) # gives Index(['Date', 'body'], dtype='object')

如果我致电table['body'],我会得到正确的内容。但是调用table['Date']给了我这个:

Traceback (most recent call last):
  File "ara.py", line 21, in <module>
    print(n_doc_set['Date'])
  File "/usr/lib/python3/dist-packages/pandas/core/frame.py", line 1969, in __getitem__
    return self._getitem_column(key)
  File "/usr/lib/python3/dist-packages/pandas/core/frame.py", line 1976, in _getitem_column
    return self._get_item_cache(key)
  File "/usr/lib/python3/dist-packages/pandas/core/generic.py", line 1091, in _get_item_cache
    values = self._data.get(item)
  File "/usr/lib/python3/dist-packages/pandas/core/internals.py", line 3211, in get
    loc = self.items.get_loc(item)
  File "/usr/lib/python3/dist-packages/pandas/core/index.py", line 1759, in get_loc
    return self._engine.get_loc(key)
  File "pandas/index.pyx", line 137, in pandas.index.IndexEngine.get_loc (pandas/index.c:3979)
  File "pandas/index.pyx", line 157, in pandas.index.IndexEngine.get_loc (pandas/index.c:3843)
  File "pandas/hashtable.pyx", line 668, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12265)
  File "pandas/hashtable.pyx", line 676, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12216)
KeyError: 'Date'

知道为什么会这样吗?我还必须声明这一切都适用于其他表格,这些表格都是英语。阿拉伯语有什么问题吗?

0 个答案:

没有答案