Adam
Adam

Reputation: 45

Why doesn't my Python function convert the column to datetime format

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

Upvotes: 2

Views: 68

Answers (1)

Hans Bambel
Hans Bambel

Reputation: 956

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

Upvotes: 3

Related Questions