【问题标题】:Multiply two pandas series matching on series index在系列索引上相乘两个熊猫系列匹配
【发布时间】:2017-10-29 17:05:27
【问题描述】:
我有两个熊猫系列
系列 1:
2016-01-31 10
2016-01-31 20
2016-03-31 30
2016-03-31 40
系列 2:
2016-01-31 2
2016-03-31 3
我想在索引上乘以系列 1 和系列 2 匹配:
回答
2016-01-31 20
2016-01-31 40
2016-03-31 90
2016-03-31 120
【问题讨论】:
标签:
pandas
series
multiplication
【解决方案1】:
将mul与参数fill_value=1一起使用:
s = s1.mul(s2, fill_value=1)
print (s)
2016-01-31 20
2016-01-31 40
2016-03-31 90
2016-03-31 120
dtype: int64
【讨论】:
-
不客气!如果我的回答有帮助,请不要忘记 accept 它 - 单击答案旁边的复选标记 (✓) 将其从灰色切换为已填充。谢谢。