Shark00n
Shark00n

Reputation: 129

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?

[Edit]

If i copy the values in a new Excel file and load this, the integers does not get converted to float. But i need to get the Values correct of the original file, so is there anything i can do?

Options dtype and converted changes the type as i need in str but as a floating number with .0

Upvotes: 0

Views: 3987

Answers (1)

intedgar
intedgar

Reputation: 681

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

Upvotes: 1

Related Questions