Python3 TypeError: cannot do slice indexing on Index with these indexers [1] of type int
读取excel时,不加header=None,则报错TypeError: cannot do slice indexing on Index with these indexers [1] of type inttemp_df = pd.read_excel(current_file)row_list = list(temp_df.loc[0,1:])column_list = list(temp
·
读取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])
更多推荐
已为社区贡献3条内容
所有评论(0)