Search code examples
pythonpandasimport-from-excel

Importing excel data with pandas showing date-time despite being date value


I've just started using pandas and I'm trying to import an excel file but I get Date-Time values like 01/01/2019 00:00:00 instead of the 01/01/2019 format. The source data is Date by the way, not Date-Time.

I'm using the following code

import pandas as pd 
df = pd.read_excel (r'C:\Users\abcd\Desktop\KumulData.xlsx')
print(df)

The columns that have date in them are "BDATE", "BVADE" and "AKTIVASYONTARIH" which correspond to 6th, 7th and 11th columns.

What code can I use to see the dates as Date format in Pandas Dataframe?

Thanks.


Solution

  • If they're already datetimes then you can extract the date part and reassign the columns:

    df[["BDATE", "BVADE", "AKTIVASYONTARIH"]] = df[["BDATE", "BVADE", "AKTIVASYONTARIH"]].apply(lambda x: x.dt.date)
    

    solution updated..