有没有办法按照数据框中其中一列的最高值对pandas数据帧列表进行排序(这些列是由数据帧共享的)?
答案 0 :(得分:2)
from pandas import DataFrame
import pandas as pd
dict1 = {"id":[1,2,3],"age":[10,20,60]}
dict2 = {"id":[4,5,6],"age":[10,20,40]}
df1 = DataFrame.from_dict(dict1)
df2 = DataFrame.from_dict(dict2)
dflist = [df1,df2]
sorteddflist= sorted(dflist,key=lambda x:x["age"].max(axis=0))
for i in sorteddflist:
print(i)