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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.