我的数据框中有以下数据:
uniquecode1 year month Name Sale
1029 2020 5 ABC 10
1029 2020 6 ABC 20
1029 2020 10 ABC 30
1029 2020 11 ABC 35
1029 2020 12 ABC 38
1050 2020 4 DEF 39
1050 2020 5 DEF 40
1050 2020 6 DEF 31
1050 2020 7 DEF 45
1050 2020 8 DEF 55
1079 2020 4 GHI 65
1079 2021 2 GHI 75
10810 2021 1 XYZ 85
假设我们坐在3月21日。对于2021年的月上限,我们将限制在3月21日减去1日,即2月21日
我们看到数据被分成不同的唯一代码组1。对于每组uniquecode1,我们在“月”列中缺少值
我对熊猫不熟悉。我试图建立一个逻辑来处理上述缺失的值。将缺少的月份和年份值插入数据时,“uniquecode1”和“name”应从各自的组值中复制,“Sale”的值应为0或NaN
有人能帮我用熊猫为它写一个代码吗? 请告诉我您可能需要的其他详细信息
您可以将带有} {a2}添加所有缺少的组合(对于不存在的值)和带有原始格式的^{} 的^{} :
month
的year
转换为datetimes,然后使用带有新0
的^{添加年份和月份的最后期限:
但不幸的是缺少} :
09-2020
,因此有必要添加^{相关问题 更多 >
编程相关推荐