简体   繁体   中英

Python Pandas read_excel without converting int to float

im reading an Excel file:

df = pd.read_excel(r'C:\test.xlsx', 'Sheet0', skiprows = 1)

The Excel file contains a column formatted General and a value like "405788", after reading this with pandas the output looks like "405788.0" so its converted as float. I need any value as String without changing the values, can someone help me out with this?

You can try to use the dtype attribute of the read_excel method.

df = pd.read_excel(r'C:\test.xlsx', 'Sheet0', skiprows = 1,
dtype={'Name': str, 'Value': str})

More information in the pandas docs: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_excel.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM