Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading