Когда я читаю свои данные, они являются объектами:
Код: Выделить всё
Date object
dtype: object
Код: Выделить всё
import pandas as pd
file = '/pathtocsv.csv'
df = pd.read_csv(file, sep = ',', encoding='utf-8-sig', usecols= ['Date', 'ids'])
df['Date'] = pd.to_datetime(df['Date'])
df['Month'] = df['Date'].dt.month
Код: Выделить всё
In [10]: df['Date'].dtype
Out[10]: dtype('O')
Код: Выделить всё
/Library/Frameworks/Python.framework/Versions/2.7/bin/User/lib/python2.7/site-packages/pandas/core/series.pyc in _make_dt_accessor(self)
2526 return maybe_to_datetimelike(self)
2527 except Exception:
-> 2528 raise AttributeError("Can only use .dt accessor with datetimelike "
2529 "values")
2530
AttributeError: Can only use .dt accessor with datetimelike values
Столбцы с датами выглядят следующим образом:
Код: Выделить всё
0 2014-01-01
1 2014-01-01
2 2014-01-01
3 2014-01-01
4 2014-01-03
5 2014-01-03
6 2014-01-03
7 2014-01-07
8 2014-01-08
9 2014-01-09
Большое спасибо!
Подробнее здесь: https://stackoverflow.com/questions/333 ... ike-values