1 回答

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超10個(gè)贊
讀取 Excel 文件的所有工作表并將其存儲(chǔ)在dictionary:
xls = pd.ExcelFile('excel_file_path.xls')
sheet_to_df_map = {}
for sheet_name in xls.sheet_names:
sheet_to_df_map[sheet_name] = xls.parse(sheet_name)
現(xiàn)在,您可以遍歷您的字典并創(chuàng)建另一個(gè)具有數(shù)據(jù)幀行數(shù)的字典,如下所示:
row_count_dict = {}
for key,val in sheet_to_df_map.items():
row_count_dict[key] = val.shape[0]
然后找到按值的row_count_dict最大值:
df_with_max_rows = max(row_count_dict, key=row_count_dict.get)
然后使用該鍵查找原始字典以獲取具有 max_rows 的數(shù)據(jù)幀:
df = sheet_to_df_map.get(df_with_max_rows)
這將是您的最終數(shù)據(jù)框。
添加回答
舉報(bào)