如果列值在过去的N个月中增加/减小,则如何在Python的时间序列数据框架内增加/减小?

发布于 2025-02-08 06:21:51 字数 44 浏览 2 评论 0原文

我正在使用客户数据,需要标记过去6个月和12个月内薪水下降或增加的客户吗?

I am working with customer data and need to flag customers who had decrease or increase in salary in last 6 and 12 months?

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

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

发布评论

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

评论(1

酒儿 2025-02-15 06:21:51

没有大量的信息,让我们假设您的时间表数据已设置,以便每行都包含每月数据。 IE第1行是一月数据,第2行是2月等。

这是实现 https ://www.statology.org/pandas-difference-between-rows/

然后,您可以使用应用程序检查delta列中的每一行,如果是正则返回值<代码>增加,否则返回值降低。您可能可以使用lambda。

我的语法可能有点不合时宜,但这是返回布尔国旗的总体想法。

df ['flag'] = df ['delta']。应用(lambda x:x&gt; 0)

Not having a ton of information, let's assume your timeseries data is set up so each row consists of monthly data. i.e row 1 is January data, row 2 is February, etc.

Here is an implementation https://www.statology.org/pandas-difference-between-rows/

Then you can use apply to check each row in the delta column and if it is positive return the value increase otherwise return the value decrease. You can probably use lambda for this.

My syntax may be a little off but this is the general idea to return a boolean flag.

df['flag']= df['delta'].apply(lambda x: x>0)

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