Get Month from date in pandas python

dt.month  is the inbuilt method to get month from date in Pandas Python.  Let’s see how to

  • Get the month from any given date in pandas python

First lets create the dataframe


import pandas as pd
import numpy as np
import datetime

date1 = pd.Series(pd.date_range('2012-1-1 12:00:00', periods=7, freq='M'))
df = pd.DataFrame(dict(date_given=date1))
print(df)

so the resultant dataframe will be

Get Month from date in pandas python 1

 

Month  function gets month value of the date

df['month_of_date'] = df['date_given'].dt.month
print(df)

so the resultant dataframe will be

Get Month from date in pandas python 2

Get Month from date in pandas python                                                                                                                Get Month from date in pandas python n