Get Day from date in pandas python

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

  • Get the day 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='D'))
df = pd.DataFrame(dict(date_given=date1))
print(df)

so the resultant dataframe will be

Get Day from date in pandas python 1

 

day function gets day value from the date

df['day_of_date'] = df['date_given'].dt.day
print(df)

so the resultant dataframe will be

Get Day from date in pandas python 2

 

Get Day from date in pandas python p                                                                                                            Get Day from date in pandas python n