Search code examples
pythonpandasxlsxdata-analysis

How to read xlsx file with out loosing data type


How to read xlsx file with out loosing data type

Example Data:

Column1                                                 Column2         
['&arg_Mode_previousMode', '&arg_Mode_nextMode']        Mode            
['arg_Mode_nextMode']                                   Switch

df = pd.ExcelFile("DF.xlsx")
df1 = df.parse("DF")

the output is return as string , but one of my column has List elements. when i use df1 in my application its unable to read as List.


Solution

  • you can use

    pd.read_excel(..., dtype= {'Column1': np.float64, 'Column1': np.int32}
    

    of course specifying the column types wisely