使用python中的移动平均线添加行
我有以下问题: 我有一个表,客户编号,日期和销售存储。客户交易可在每个月的第一个月提供。客户可能没有每月下订单。 The table looks like this:
ID | Date | Revenues |
---|---|---|
1 | 2021-05-01 | 100 |
1 | 2021-07-01 | 200 |
1 | 2021-08-01 | 100 |
1 | 2021-10-01 | 200 |
2 | 2021-12-01 | 300 |
2 | 2022-01-01 | 400 |
Now I want to add a certain number of rows to each group whose date is from today for a certain number of months in the future. ID应保持不变,日期应增加一个月,而离职列应用移动平均方法填充。
The table should look like this:
ID | Date | Revenues |
---|---|---|
1 | 2021-05-01 | 100 |
1 | 2021-07-01 | 200 |
1 | 2021-08-01 | 100 |
1 | 2021-10-01 | 200 |
1 | 2022-04-01 | 150 |
1 | 2022-05-01 | 150 |
2 | 2021-12-01 | 300 |
2 | 2022-01-01 | 400 |
2 | 2022-04-01 | 350 |
2 | 2022-05-01 | 350 |
How can I solve this problem? 感谢您的帮助 :)
I have the following problem:
I have a table in which the customer number, the date and the sales are stored. The customer transactions are available on the first of each month. It may happen that a customer has not placed an order every month. The table looks like this:
ID | Date | Revenues |
---|---|---|
1 | 2021-05-01 | 100 |
1 | 2021-07-01 | 200 |
1 | 2021-08-01 | 100 |
1 | 2021-10-01 | 200 |
2 | 2021-12-01 | 300 |
2 | 2022-01-01 | 400 |
Now I want to add a certain number of rows to each group whose date is from today for a certain number of months in the future. The ID should remain the same, the date should be increased by one month and the turnover column should be filled with the moving average method.
The table should look like this:
ID | Date | Revenues |
---|---|---|
1 | 2021-05-01 | 100 |
1 | 2021-07-01 | 200 |
1 | 2021-08-01 | 100 |
1 | 2021-10-01 | 200 |
1 | 2022-04-01 | 150 |
1 | 2022-05-01 | 150 |
2 | 2021-12-01 | 300 |
2 | 2022-01-01 | 400 |
2 | 2022-04-01 | 350 |
2 | 2022-05-01 | 350 |
How can I solve this problem?
Thank you for your help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解您:
打印:
If I understand you correctly:
Prints: