首页 > 解决方案 > 使用 pandas read_excel 丢失浮点数据类型的精度

问题描述

我正在使用 pandas read_excel 函数从 excel 中读取以下数据。当我读取数据时,我丢失了小数并且数字被格式化为整数。

excel数据

# Read gdp data
df_gdp = pd.read_excel("~/Data/gdp_per_capita.xlsx", dtype={'Inflows': float, 'USD': float}, sheet_name="Data")

date       Inflows  USD
1980-12-31   0      0
1981-12-31   0      0
1982-12-31   0      0
1983-12-31   0      0

我也尝试将数据读取为float,但它也不起作用。

标签: pythonpandas

解决方案


推荐阅读