Populate current date in pandas python can be done by using to_datetime() function. Let’s see how to
- Populate current date in pandas python
- Populate current date with string format in pandas python
First let’s create a dataframe
import pandas as pd import numpy as np df1 = { 'State':['Arizona AZ','Georgia GG','Newyork NY','Indiana IN','Florida FL'], 'Score1':[4,47,55,74,31]} df1 = pd.DataFrame(df1,columns=['State','Score1']) print(df1)
df1 will be
Populate current date in pandas python:
Populating current date in pandas can be done by using to_datetime() function with “today” argument as shown below.
df1['date'] = pd.to_datetime('today') print(df1)
so the resultant dataframe will be
Populate current date in python pandas with string format:
Populating current date in pandas with string format can be done by using to_datetime() function and strftime() function as shown below.
df1['date'] = pd.to_datetime('today').strftime("%m/%d/%Y") print(df1)
so the resultant dataframe will have date column in string format