以下来自dataferame的提取(位于底部)具有带索引的区域和Quardate的多索引,我希望获取新的数据帧相同的索引和只有每个区域的最大日期的行..我无法弄清楚如何访问数据框索引值。 我想是这样的:使用索引名称通过Pandas中的多索引框架选择新数据帧
most_recent_date=totRegscore.region.Quradate.max()
刚刚告诉我,“数据帧”对象有没有属性“区域” 我也想这样做:
last_quarter = most_recent_date - relativedelta(months=3)
和做类似:
quarter_score_diff = [most_recent_date, last_quarter].diff()
在这里,这一个答案,我不能获得工作的一个变种... Summary calculations on a Pandas Dataframe 样品输入:
Score1 Score2
region Quradate
North_Central-Birmingham-Tuscaloosa-Anniston 2010-01-15 47 50
2010-04-15 45 60
2010-07-15 45 40
我觉得在这一点上我的主要问题是不能够使用索引名来选择穆蒂索引数据帧的特定行.... 所以在得到一个DF只有当前日期和一个用刚刚过去的季度日期两个dataframes的差异看起来像 输出示例:
Score1 Score2
region Quradate
quarterly_diff North_Central-Birmingham-Tuscaloosa-Anniston 2010-07-15 7 6
quarterly_diff Huntsville 2010-07-15 6 5
可能只是我,但如果你添加样本输入和样本想要的输出,创建工作解决方案会容易得多 –
编辑问题以澄清输入和输出(我希望) – dartdog
什么可以帮助显示一些代码生成你开始使用的确切数据框,这看起来像你需要使用'''''',见[这里](http://pandas.pydata.org/pandas-docs/dev/indexing.html#cross -section-hierarchy-index) – Jeff