读取excel时,不加header=None,则报错TypeError: cannot do slice indexing on Index with these indexers [1] of type int


    temp_df = pd.read_excel(current_file)
    row_list = list(temp_df.loc[0,1:])
    column_list = list(temp_df.loc[1:,0])
    TypeError: cannot do slice indexing on Index with these indexers [1] of type int

改为:

        temp_df = pd.read_excel(current_file,header=None)
        row_list = list(temp_df.loc[0,1:])
        column_list = list(temp_df.loc[1:,0])

则没有问题。

或者将.loc改为iloc,如:

    temp_df = pd.read_excel(current_file)
    row_list = list(temp_df.iloc[0,1:])
    column_list = list(temp_df.iloc[1:,0])

在这里插入图片描述

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐