Is there a way to sort a list of pandas dataframes by the highest value of one of the columns in the dataframes (the columns are shared by the dataframes)?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With