我是靠谱客的博主 贤惠冷风,这篇文章主要介绍找出Pandas 数组行中的 第二大元素 排序,现在分享给大家,希望可以做个参考。

import numpy as np
import pandas as pd

df = pd.DataFrame({
    'a': [4, 5, 3, 1, 2],
    'b': [20, 10, 40, 50, 30],
    'c': [25, 20, 5, 15, 10]
})


def sort_value(column):
    new_column = column.sort_values(ascending = False)
    return new_column.iloc[1]
    
def second_largest(df):
    return df.apply(sort_value)
    
print second_largest(df)
a     4
b    40
c    20
dtype: int64


最后

以上就是贤惠冷风最近收集整理的关于找出Pandas 数组行中的 第二大元素 排序的全部内容,更多相关找出Pandas内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(126)

评论列表共有 0 条评论

立即
投稿
返回
顶部