pandas过去每列的最大值
时间: 2023-10-11 07:13:20 浏览: 127
要找出pandas中每列的最大值,可以使用`df.max()`函数。以下是一个示例代码:
```python
import pandas as pd
# 构建df
df = pd.DataFrame({
'水果': ['苹果', '香蕉', '西瓜', '葡萄', '柚子', '芒果'],
'公司': ['A1', 'A1', 'A2', 'A2', 'A2', 'A3'],
'重量': [1, 2, 3, 4, 5, 6],
'数量': [3, 2, 5, 10, 10, 6]
})
# 获取每列的最大值
max_values = df.max()
# 输出结果
print(max_values)
```
这段代码中,我们构建了一个DataFrame `df`,然后使用`df.max()`函数获取了每列的最大值,并将结果存储在`max_values`变量中。最后,我们打印了最大值结果。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [Python利用pandas获取每行最大值和最小值](https://blog.csdn.net/u013541325/article/details/126677558)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [pandas获取分组里最大值所在的行方法](https://blog.csdn.net/summerriver1/article/details/125693119)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文