首页 > 解决方案 > 如何转换excel文件的数据值

问题描述

这是我的excel文件

column_list = []
df_column = pd.read_excel(r'data/health-insurance.xlsx', sheet_name='Sheet1').columns
for i in df_column:
    column_list.append(i)
converter = {col: str for col in column_list} 
df_actual = pd.read_excel('data/health-insurance.xlsx', converters=converter)
df_actual['New York City','Estimate'][0]

我尝试过使用 lambda、astype、to_numeric 函数,但没有成功。

标签: python

解决方案


根据https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html,DataFrame对象没有“解析”功能。


您可以将每一行读入一个数组,然后将该数组加载到文件对象中。


推荐阅读