后台:在处理Excel的时候,遇到这样的场景,根据某个列,将当前表格拆分成多个sheet页,方便后期分析处理。基于以上需求,这里结合pandas,实现了这个逻辑。示例数据:importpandasaspdimportnumpyasnp#列名和数据显示pd.set_option('display.unicode.ambiguous_as_wide',True)pd.set_option('display.unicode.east_asian_width',True)#显示所有列pd.set_option('display.max_columns',None)#显示所有行pd.set_option('display.max_rows',None)importpandas_profilingdf=pd.read_excel("Testdata.xlsx")writer=pd.ExcelWriter("data.xlsx")foriindf["group"].drop_duplicates().to_list():groupname=iprint("SplitID:",groupname)tmp_df=df[df["Grouping"]==groupname]tmp_df.to_excel(writer,sheet_name=groupname)writer.save()
