Reputation: 513
For example, if i have:
list=[df1,df2,df3,df4]
How can python identify and get the df with the maximum number of rows? or len And if you have 2 dfs with the min or max value, it can take any of these.
Upvotes: 0
Views: 193
Reputation: 706
You can use max()
function with a key that specifies the way you look at the magnitude of your data:
max_df = max(list_, key=len)
min_df = min(list_, key=len)
NOTE there is an implicit mistake in your code that you might wanna correct. you have overwritten the python keyword list
. add an underscore for example to the end of it to avoid any unwanted error
UPDATE: the key=lambda x:len(x)
replaced by key=len
, thanks to @rafaelc comment
Upvotes: 2