Pandas read excel: don't parse numbers

I am working with python pandas and MS excel to edit an xlsx file. I repeat these programs back and forth. The file contains several columns with text that looks like numbers, for example,

enter image description here

If I read it, I get

pd.read_excel ('test.xlsx')
     A
0    1
1  100

and

pd.read_excel ('test.xlsx').dtypes
A    int64
dtype: object

My question is: how can I read text as text? It is impossible to analyze it after reading, because part of the information (i.e. leading zeros) is lost when converting to a number.

Thank you for your help.

+4
source share
3 answers

According to this question , this is a known issue with pandas.

+3
source

( , ), "":

>>> pd.read_excel('test.xlsx', converters={'A': str})
     A
0  001
1  100
>>> pd.read_excel('test.xlsx', converters={'A': str}).dtypes
A    object
dtype: object
+11

if you can convert the file to CSV, dtype = str should work.

pd.read_csv('test.csv', dtype=str)

Source: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_excel.html

+1
source

Source: https://habr.com/ru/post/1546668/


All Articles