数据多维处理
数据多维处理:
import pandas as pd #多层索引 new_ind=['begin','end','ID'] # df1=pd.read_excel(r'F:\小高天天乐\python_PM\AUTO_DATA\test00100\1.xlsx') df1=pd.read_excel(r'F:\小高天天乐\python_PM\AUTO_DATA\test00100\1.xlsx').set_index(new_ind) # df2=pd.read_excel(r'F:\小高天天乐\python_PM\AUTO_DATA\test00100\2.xlsx') df2=pd.read_excel(r'F:\小高天天乐\python_PM\AUTO_DATA\test00100\2.xlsx').set_index(new_ind) print(df1) print('*'*50) print(df2) #数据堆叠 stack_df1=pd.DataFrame(df1.stack(),columns=['value_1']) stack_df2=pd.DataFrame(df2.stack(),columns=['value_2']) print(stack_df1,stack_df2) #数据合并 # merge_df=stack_df1.merge(stack_df2,on=new_ind,how='outer') # merge_df=stack_df1.merge(stack_df2,left_index=True,right_index=True) merge_df_new=stack_df1.merge(stack_df2,left_index=True,right_index=True) print(merge_df_new) #数据比较 merge_df_new['tag']=merge_df_new.apply(lambda f:'正常' if f['value_1']==f['value_2'] else '异常',axis=1) print(merge_df_new)