如果列值在过去的N个月中增加/减小,则如何在Python的时间序列数据框架内增加/减小?
我正在使用客户数据,需要标记过去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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有大量的信息,让我们假设您的时间表数据已设置,以便每行都包含每月数据。 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 valueincrease
otherwise return the valuedecrease
. 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)