熊猫 - 最小和最大功能

发布于 2025-02-08 09:14:40 字数 1250 浏览 1 评论 0原文

的最小功能和最大功能,

独特物品列表的方法,然后打印每列的最小值和最大值

示例:

T恤销售
我想知道是否有一种获取我正在使用python200696
Feb500359855
3月685252100
JAN885598 266266
FEB10012231000
MAR882298754

我想在这里做的是找到每个类别的最低和最大销售额

所需的输出

一个月最大销售最小销售最大销售最大帽子销售最大帽子销售最大销售最大销售最低销售最小销售
1月885757598598 598696 266266
FEB10015002233591000855
MAR882685298252754100

有一个简单的方法是否必须分别为每列获得最小和最大的情况,然后将其附加到DF?

谢谢

I am playing with the min and max functions in python

I'm wondering if there's a way to get a unique list of items and then print the min and max values of each column

example:

MonthT-shirt SalesHat Salesshort Sales
Jan757200696
Feb500359855
Mar685252100
Jan885598266
Feb10012231000
Mar882298754

What I'd like to do here is find the min and max sales per month for each category

Desired Output

MonthMax TS SalesMin TS SalesMax Hat SalesMin Hat SalesMax Short SalesMin short Sales
Jan885757598598696266
Feb10015002233591000855
Mar882685298252754100

Is there a simple way to do this or is it a case that I'll have to get the min and max for each column separately and append to a DF?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最后的乘客 2025-02-15 09:14:41
import pandas as pd

df = pd.DataFrame({'month': ['Jan', 'Feb', 'Jan', 'Feb'],
                   't-shirt': [1, 2, 3, 4],
                   'hat': [4, 3, 2, 1]})

res = df.groupby(by='month').agg(['min', 'max'])
import pandas as pd

df = pd.DataFrame({'month': ['Jan', 'Feb', 'Jan', 'Feb'],
                   't-shirt': [1, 2, 3, 4],
                   'hat': [4, 3, 2, 1]})

res = df.groupby(by='month').agg(['min', 'max'])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文