0

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.

cs95
  • 379,657
  • 97
  • 704
  • 746
Rakesh Bhagam
  • 117
  • 1
  • 2
  • 9
  • See the answer here: https://stackoverflow.com/questions/48008191/attributeerror-pandasexprvisitor-object-has-no-attribute-visit-ellipsis-us It explains how to convert a column of strings to a column of lists. – cs95 Feb 20 '18 at 08:35
  • it's converting only one column. I need total data frame conversion in single command line. – Rakesh Bhagam Feb 20 '18 at 08:45
  • `import ast; df = df.apply(ast.literal_eval)` – cs95 Feb 20 '18 at 08:46

1 Answers1

-1

you can use

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

of course specifying the column types wisely

quest
  • 3,576
  • 2
  • 16
  • 26