【发布时间】:2019-11-29 12:53:40
【问题描述】:
我有一个如下所示的数据集:
ID Date Input1 Input2 1.Eff 2.Eff Qty Time
3 1/2/2019 A A 32.08 76.64 5 200
3 1/3/2019 A A 55.95 41.18 10 100
3 1/4/2019 A A 56.61 50 5 300
3 1/4/2019 A B 56.61 35.67 10 300
在输出字段中,我想要两列 new_Eff 和 new_time 将从上述数据计算,计算 New_time 和 New_eff 的逻辑是: 1,如果ID和Date组合如果有一个行项目,那么1.Eff将等于new_eff,new_time将等于时间。 所以对于第 1 行和第 2 行的输出将是
ID Date Input1 Input2 1.Eff 2.Eff Qty Time new_time new_EFf
3 1/2/2019 A A 32.08 76.64 5 200 32.08 200
3 1/3/2019 A A 55.95 41.18 10 100 55.95 100
在第 3 行和第 4 行中,日期没有变化,因此 new_Eff 将等于第 1 天 2.Eff 和时间将等于时间/数量,因此第 3 行输出将是:
ID Date Input1 Input2 1.Eff 2.Eff Qty Time new_time new_EFf
3 1/4/2019 A A 56.61 50 5 300 300/5=60 41.48 (on 3rd 2.Eff is 41.48)
在第 4 行 new_time 将是总时间-60=300-60=240 并且 new_eff 将是 new_time/Qty=240/5=48
ID Date Input1 Input2 1.Eff 2.Eff Qty Time new_time new_EFf
3 1/4/2019 A B 56.61 35.67 10 300 240 48
所以输出表将如下所示:
ID Date Input1 Input2 1.Eff 2.Eff Qty Time new_time new_EFf
3 1/2/2019 A A 32.08 76.64 5 200 32.08 200
3 1/3/2019 A A 55.95 41.18 10 100 55.95 100
3 1/4/2019 A A 56.61 50 5 300 60 41.48
3 1/4/2019 A B 56.61 35.67 10 300 240 48
当同一日期有多行时,谁能帮助我如何执行这些反向计算..
提前致谢
【问题讨论】:
-
如果有超过 2 行具有相同的 id 和日期会发生什么?
-
不会是这样,要么是 1,要么是最大 2-@Dev Khadka
标签: python pandas python-2.7 dataframe metadata