pandas获取最大值/最小值对应的index

生成数据

import pandas as pd

df: pd.DataFrame = pd.DataFrame([
    [1, 4.2],
    [70, 0.03],
    [5, 0]
], columns=['one', 'two'])
onetwo
014.2
1700.03
250

最大值对应的index

print(df.idxmax())
one    1
two    0
dtype: int64

最小值对应的index

print(df.idxmin())
one    0
two    2
dtype: int64
  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,我明白了。这是一个与编程相关的问题,我可以提供一些帮助。 您可以使用Python的pandas库读取Excel文件并统计列的值。下面是一个参考代码,可以根据您的具体情况进行修改: ```python import pandas as pd import glob # 读取所有Excel文件 files = glob.glob('*.xlsx') df_list = [] # 循环读取每个Excel文件 for file in files: df = pd.read_excel(file) df_list.append(df) # 将所有据合并为一个DataFrame df_all = pd.concat(df_list, ignore_index=True) # 统计第八列的值 col_8_greater_than_80 = (df_all.iloc[:, 7] > 80).sum() col_8_greater_than_120 = (df_all.iloc[:, 7] > 120).sum() col_8_greater_than_150 = (df_all.iloc[:, 7] > 150).sum() col_8_max = df_all.iloc[:, 7].max() # 统计第九列的值 col_9_count = df_all.iloc[:, 8].count() col_9_max = df_all.iloc[:, 8].max() col_9_min = df_all.iloc[:, 8].min() # 找到第九列最大值的行 max_row = df_all.iloc[:, 8].idxmax() # 取出第九列最大值的八列据 col_8_of_max_row = df_all.iloc[max_row, 0:7].tolist() # 将结果写入新Excel文件 df_result = pd.DataFrame({'col_8_greater_than_80': [col_8_greater_than_80], 'col_8_greater_than_120': [col_8_greater_than_120], 'col_8_greater_than_150': [col_8_greater_than_150], 'col_8_max': [col_8_max], 'col_9_count': [col_9_count], 'col_9_max': [col_9_max], 'col_9_min': [col_9_min], 'col_8_of_max_row': col_8_of_max_row}) df_result.to_excel('result.xlsx', index=False) ``` 请注意,此代码假定Excel文件位于与脚本相同的目录,并且每个文件具有相同的格式:所有据都在第一个工作表,第一行是标题行,据从第二行开始。如果您的情况有所不同,请相应地修改代码。 如果您需要进一步的帮助,请让我知道。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

呆萌的代Ma

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值