【发布时间】:2019-06-11 21:01:10
【问题描述】:
作为对发送的年度报告的合理性检查,我想根据上一年提交的期末值确保一年的陈述值是正确的。通过这个多索引数据框,我尝试解释我的问题:
import random
col3=[0,0,0,0,2,4,6,0,0,0,100,200,300,400]
col4=[0,0,0,0,4,6,8,0,0,0,200,900,400, 500]
d = {'Unit': [1, 1, 1, 1, 2, 2, 2, 3, 4, 5, 6, 6, 6, 6],
'Year': [2014, 2015, 2016, 2017, 2015, 2016, 2017, 2017, 2014, 2015, 2014, 2015, 2016, 2017], 'col3' : col3, 'col4' : col4 }
df = pd.DataFrame(data=d)
df.groupby(['Unit', 'Year']).sum()
我想要做的是创建一个带有比率的附加列。例如:Unit 2 year 2016 col3/ Unit 2 year 2015 col 4 = 4/4 = 1。我的下一步是查看比率是否为 1。我在此数据框中放置了一个示例,其中比率不是 1 .这原则上是我感兴趣的案例,我想确定那个数据点。
我遇到的一个问题是我的数据框中有很多零。
感谢您的任何意见!
仁
【问题讨论】:
标签: python pandas dataframe multi-index