I have a Dataframe, df, with the following column:
df[\'ArrivalDate\'] =
...
936 2012-12-31
938 2012-12-29
965 2012-12-31
966 2012-12-31
967 2012-1
Best way found!!
the df['date_column']
has to be in date time format.
df['month_year'] = df['date_column'].dt.to_period('M')
You could also use D
for Day, 2M
for 2 Months etc. for different sampling intervals, and in case one has time series data with time stamp, we can go for granular sampling intervals such as 45Min
for 45 min, 15Min
for 15 min sampling etc.