'How to stop python auto date parsing while reading a excel file

i need to read a excel file without changing any date , time format , float format and convert to data-frame. This is working fine if i convert the excel to CSV and read it using read_csv() .

eg:

import pandas as pd
import numpy as np
#code for reading excel
df=pd.read_excel("605.xlsx",parse_dates=False,sheet_name="Group 1",keep_default_na=False,dtype=str)
print("df_excel:")
#code for reading csv   

df1=pd.read_csv("Group 1.csv",parse_dates=False,dtype=str,na_filter = False)
 print("df_csv:",df1)

output: enter image description here

in the above code parse_dates=False is working fine while reading CSV file, but parse_dates=False is not working in read_excel()

Expected output: Need the exact excel data into a data-frame without changing the date , time format.



Solution 1:[1]

From the Pandas docs on the parse_dates parameter for read_excel():

If a column or index contains an unparseable date, the entire column or index will be returned unaltered as an object data type. If you don`t want to parse some cells as date just change their type in Excel to “Text”.

You could try this:

df = pd.read_excel("605.xlsx",parse_dates=False,sheet_name="Group1",keep_default_na=False,dtype=str, converters={'as_at_date': str})

Explicitly converting the date column to string might help.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lok1