I have a pandas DataFrame with index column = date.
Input:
value
date
1986-01-31 22.93
1986-02-28 15.46
This will do the trick and no imports necessary. Numpy has a dtype datetime64 which by default pandas sets to [ns] as seen by checking the dtype. You can change this to month, which will start on the first of the month by accessing the numpy array and changing the type.
df.date = pd.to_datetime(df.date.values.astype('datetime64[M]'))
It would be nice if pandas would implement this with their own astype() method but unfortunately you cannot.
The above works for data as datetime values or strings, if you already have your data as datetime[ns] type you can omit the pd.to_datetime() and just do:
df.date = df.date.values.astype('datetime64[M]')