Home > front end >  Why doesn't my Python function convert the column to datetime format
Why doesn't my Python function convert the column to datetime format

Time:03-01

I am trying to write a function to convert a column to datetime format (has to be in a function). When i run below however, it doesnt seem to do anything. Any ideas where i am going wrong?

data = pd.DataFrame({'DOB': {1: '01/04/1973', 2: '01/03/1979', 3: '22/06/2005', 4: '01/03/1994'}})

def update_col(df_name):
    pd.to_datetime(df_name['DOB'])

update_col(data)
data

CodePudding user response:

You don't save the change to the dataframe:

data = pd.DataFrame({'DOB': {1: '01/04/1973', 2: '01/03/1979', 3: '22/06/2005', 4: '01/03/1994'}})

def update_col(df_name):
    df_name['DOB'] = pd.to_datetime(df_name['DOB'])

update_col(data)
data
  • Related