简体   繁体   English

Python Pandas read_excel 无需将 int 转换为 float

[英]Python Pandas read_excel without converting int to float

im reading an Excel file:我正在阅读一个 Excel 文件:

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. Excel 文件包含一个格式为 General 的列和一个类似“405788”的值,在用 Pandas 读取后,输出看起来像“405788.0”,因此它被转换为浮点数。 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.您可以尝试使用 read_excel 方法的 dtype 属性。

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熊猫文档中的更多信息: https : //pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_excel.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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