如何在python/ colab的循环中添加一个月开始的日期?
我需要通过桌子创建您的建议。
我有一个看起来像这样的桌子。
月 | 部 | 总支出 |
---|---|---|
1月至18日 | DOJ | 625000 |
625000 | DOJ 975000 1月至18日DOJ | 650000 JAN-18 JAN-18 DOJ 625000 |
975000 | DOJ | JAN |
DOJ | 975000 | - |
DOJ | JAN | 650000 |
650000 | 18 | DOJ |
18 | DOJ | - |
DOJ | 625000 | DOJ |
18 | 625000 | JAN |
- -18 | DOJ | 625000 |
JAN-18 | 975000 | DOJ |
DOJ | DOJ | 650000 |
DOJ | FEB | DOJ 975000 JAN-18 DOJ 650000 2月至18日DOJ 625000 DOJ 625000 FEB-18 DOJ 975000 |
650000 | 650000 | DOJ |
18 | 625000 | DOJ |
DOJ | - | 18 |
625000 | 975000 DOJ | 650000 |
Feb- | DOJ 975000 DOJ 6500 doj | 975000 |
Feb-18 | doj 620000 doj | 625000 |
Feb -18 | DOJ | 975000 |
FEB-18 | DOJ | 650000 |
,这一直持续到DOJ和其他12个部门的5月22日。
我不能旋转这张表,因为在丢失日期的第一列中重复了 Tableau将增加数字,Python会丢下错误,例如
ValueError: Index contains duplicate entries, cannot reshape
每个月只有12个条目(每月12天)。我想在每个月开始时添加数字1到12,以便条目具有一个唯一的ID,可以用于df1.pivot(index ='note',columns ='dmot剂',values ='总计支出估计')
新表格应像
月 | 部 | 总支出 |
---|---|---|
1-1月1日 | DOJ | 625000 |
2-JAN-18 | DOJ 975000 DOJ | 975000 |
3-JAN-18-JAN-18 | DOJ | 650000 |
4-JAN-JAN-18-JAN-18 | DOJ | 625000 |
5-JAN- JAN-- JAN-- JAN-- JAN-- 18 | DOJ | 975000 |
6-JAN-18 | DOJ | 650000 |
7-JAN-18 | DOJ | 625000 |
8-JAN-18 | DOJ | 975000 |
9-JAN-18 | DOJ | 650000 DOJ 650000 |
10-JAN-18 | 625000 | DOJ |
DOJ | 625000 | 11 |
-JAN-JAN-18 | DOJ | 650000 |
1-FEB-18 | DOJ | 625000 |
2-FEB-18 | DOJ | 975000 |
-18 | DOJ | 650000 |
-FEB-18 | DOJ | 625000 |
5-FEB-18 | DOJ | 975000 |
FEB-18 | 6 | 3- FEB |
- | 4 | 625000 |
8-FEB-18 | DOJ | 975000 |
9-FEB-18 | DOJ | 650000 |
10 -FEB | -18 DOJ | 650000 |
11-FEB-18 | DOJ | 650000 |
12-FEB-18 | DOJ | 650000 |
,我将感谢您的建议。请帮助我,并建议如何修复此专栏。先感谢您。
I need your kind suggestions with a table creation.
I have a table that looks like this.
Month | Department | Total Expenditure |
---|---|---|
Jan-18 | DOJ | 625000 |
Jan-18 | DOJ | 975000 |
Jan-18 | DOJ | 650000 |
Jan-18 | DOJ | 625000 |
Jan-18 | DOJ | 975000 |
Jan-18 | DOJ | 650000 |
Jan-18 | DOJ | 625000 |
Jan-18 | DOJ | 975000 |
Jan-18 | DOJ | 650000 |
Jan-18 | DOJ | 625000 |
Jan-18 | DOJ | 975000 |
Jan-18 | DOJ | 650000 |
Feb-18 | DOJ | 625000 |
Feb-18 | DOJ | 975000 |
Feb-18 | DOJ | 650000 |
Feb-18 | DOJ | 625000 |
Feb-18 | DOJ | 975000 |
Feb-18 | DOJ | 650000 |
Feb-18 | DOJ | 625000 |
Feb-18 | DOJ | 975000 |
Feb-18 | DOJ | 650000 |
And this goes on till May-22 for DOJ and 12 other departments.
I cannot pivot this table, because having duplicates in the first column where the date is missing
Tableau will add the numbers up, and Python will throw an error such as
ValueError: Index contains duplicate entries, cannot reshape
Every month has 12 entries only (12 days a month). I want to add numbers 1 to 12 at the beginning of each Month column so the entries have a unique ID that i can use for df1.pivot(index='Month',columns='Department', values='Total Expenditure Estimate')
The new table should look like
Month | Department | Total Expenditure |
---|---|---|
1-Jan-18 | DOJ | 625000 |
2-Jan-18 | DOJ | 975000 |
3-Jan-18 | DOJ | 650000 |
4-Jan-18 | DOJ | 625000 |
5-Jan-18 | DOJ | 975000 |
6-Jan-18 | DOJ | 650000 |
7-Jan-18 | DOJ | 625000 |
8-Jan-18 | DOJ | 975000 |
9-Jan-18 | DOJ | 650000 |
10-Jan-18 | DOJ | 625000 |
11-Jan-18 | DOJ | 975000 |
12-Jan-18 | DOJ | 650000 |
1-Feb-18 | DOJ | 625000 |
2-Feb-18 | DOJ | 975000 |
3-Feb-18 | DOJ | 650000 |
4-Feb-18 | DOJ | 625000 |
5-Feb-18 | DOJ | 975000 |
6-Feb-18 | DOJ | 650000 |
7-Feb-18 | DOJ | 625000 |
8-Feb-18 | DOJ | 975000 |
9-Feb-18 | DOJ | 650000 |
10-Feb-18 | DOJ | 650000 |
11-Feb-18 | DOJ | 650000 |
12-Feb-18 | DOJ | 650000 |
I will appreciate your kind suggestions. Please kindly help me out and advise how to fix this column. Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
打印:
Try:
Prints: