Python KeyError для столбца InvoiceDate - PullRequest
0 голосов
/ 16 июня 2020

Впервые здесь Python и надеялся, что кто-то может мне помочь. Я пытаюсь запустить следующий код.

df['InvoiceMonth'] = df['InvoiceDate'].apply(get_month)
grouping = df.groupby('CustomerID')['InvoiceMonth']
df['CohortMonth'] = grouping.transform('min')
df.tail()

, но обнаружил ошибки

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "<ipython-input-26-911ade207098>", line 2, in <module>
    df['InvoiceMonth'] = df['InvoiceDate'].apply(get_month)

  File "C:\Users\Ytee\Anaconda3\lib\site-packages\pandas\core\frame.py", line 2800, in __getitem__
    indexer = self.columns.get_loc(key)

  File "C:\Users\Ytee\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 2648, in get_loc
    return self._engine.get_loc(self._maybe_cast_indexer(key))

  File "pandas\_libs\index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc

  File "pandas\_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc

  File "pandas\_libs\hashtable_class_helper.pxi", line 1618, in pandas._libs.hashtable.PyObjectHashTable.get_item

  File "pandas\_libs\hashtable_class_helper.pxi", line 1626, in pandas._libs.hashtable.PyObjectHashTable.get_item

KeyError: 'InvoiceDate'

Кто-нибудь знает, как я могу это исправить? Кажется, проблема со столбцом InvoiceDate. Заранее спасибо!

...