您可以通过选择包含'QC值'的行来使用np.append
如果你有像这样的数据帧
print(df1)
C D E F G H I J K L QC
0 254 95 0 34543 43 32.0 4 4 4 4 Q23
1 255 59 1 43 tre NaN r5 54 567 564 Q23
2 256 50 7 65 NaN 76557.0 65 65 5 5 Q23print(df2)
C D E F G H I J K L QC
0 254 95 0 34543 43 32.0 4 4 4 4 Q24
1 255 59 1 43 tre NaN r5 54 567 564 Q24
2 256 50 7 65 NaN 76557.0 65 65 5 5 Q24然后一个for循环来分配列将有助于你,即
for i in [df1,df2]:
q = i['QC'].unique()[0]
i.columns = np.append(mdf[mdf['QC'] == q].values[0][1:],['QC'])
print([df1,df2][ US CH JP CE OV NON DK TOT N KK QC
0 254 95 0 34543 43 32.0 4 4 4 4 Q23
1 255 59 1 43 tre NaN r5 54 567 564 Q23
2 256 50 7 65 NaN 76557.0 65 65 5 5 Q23,
US ZZ JP ME KP NON DK TOT E LK QC
0 254 95 0 34543 43 32.0 4 4 4 4 Q24
1 255 59 1 43 tre NaN r5 54 567 564 Q24
2 256 50 7 65 NaN 76557.0 65 65 5 5 Q24]