Extracting just Month and Year separately from Pandas Datetime column

I have a Dataframe, df, with the following column:

     ArrivalDate
936   2012-12-31
938   2012-12-29
965   2012-12-31
966   2012-12-31
967   2012-12-31
968   2012-12-31
969   2012-12-31
970   2012-12-29
971   2012-12-31
972   2012-12-29
973   2012-12-29

The elements of the column are pandas.tslib.Timestamp type. I want to extract the year and month.

Here's what I've tried:

df['ArrivalDate'].resample('M', how = 'mean')

which throws the following error:

Only valid with DatetimeIndex or PeriodIndex 

Then I tried:

df['ArrivalDate'].apply(lambda(x):x[:-2])

which throws the following error:

'Timestamp' object has no attribute '__getitem__' 

My current solution is

df.index = df['ArrivalDate']

Then, I can resample another column using the index.

But I'd still like a method for reconfiguring the entire column. Any ideas?

← Назад к списку