我有一个如下所示的 df 。它包含每月 1-12 月的费用。我想创建一个新列,其中包含每 12 行(第 1-12 个月)的成本总和的百分比。因此,它将获取 12 行的总和并计算成本中值的百分比。我真的不知道从哪里开始。谢谢你的帮助!
输入:
| Name | Month | Costs |
|----------|--------|-------|
| Painting | 1 | 1000 |
| Painting | 2 | 0 |
| Painting | 3 | 0 |
| Painting | 4 | 0 |
| Painting | 5 | 1000 |
| Painting | 6 | 0 |
| Painting | 7 | 0 |
| Painting | 8 | 0 |
| Painting | 9 | 1000 |
| Painting | 10 | 0 |
| Painting | 11 | 0 |
| Painting | 12 | 1000 |
| Repair | 1 | 0 |
| Repair | 2 | 0 |
| Repair | 3 | 0 |
| Repair | 4 | 2500 |
| Repair | 5 | 0 |
| Repair | 6 | 0 |
| Repair | 7 | 5000 |
| Repair | 8 | 0 |
| Repair | 9 | 0 |
| Repair | 10 | 2500 |
| Repair | 11 | 0 |
| Repair | 12 | 0 |
想要的输出:
| Name | Period | Costs | Percentages |
|----------|--------|-------|-------------|
| Painting | 1 | 1000 | 25% |
| Painting | 2 | 0 | 0% |
| Painting | 3 | 0 | 0% |
| Painting | 4 | 0 | 0% |
| Painting | 5 | 1000 | 25% |
| Painting | 6 | 0 | 0% |
| Painting | 7 | 0 | 0% |
| Painting | 8 | 0 | 0% |
| Painting | 9 | 1000 | 25% |
| Painting | 10 | 0 | 0% |
| Painting | 11 | 0 | 0% |
| Painting | 12 | 1000 | 25% |
| Repair | 1 | 0 | 0% |
| Repair | 2 | 0 | 0% |
| Repair | 3 | 0 | 0% |
| Repair | 4 | 2500 | 25% |
| Repair | 5 | 0 | 0% |
| Repair | 6 | 0 | 0% |
| Repair | 7 | 5000 | 50% |
| Repair | 8 | 0 | 0% |
| Repair | 9 | 0 | 0% |
| Repair | 10 | 2500 | 25% |
| Repair | 11 | 0 | 0% |
| Repair | 12 | 0 | 0% |
POPMUISE
相关分类