sub设置一个多级数据框,按Python中每个第二级索引的最高值设置
我有一个多级索引数据框,看起来像下图。我已经对Perc_viewed列的较高的第二级索引进行了排序。因此,对于每个第一级索引,首先列出男性(M)或女性(F)的较高索引。现在,我想仅访问第一级索引值和第二级索引值的第一个值(顶部一个) - 只有这两个索引值并在我的写入中使用它们作为每个类别中的“顶部”。我该怎么做,请
此数据的另一种视图如下。在这种情况下,我首先突出显示的值是我唯一要访问的值。
I have a multilevel index dataframe that looks like the image below. I have sorted the second level index on the higher of the perc_viewed column. So for each 1st level index, the higher of Male(M) or Female(F) is listed first. Now I want to access just the 1st level index values and the first of the second level index value (the top one) -- only those two and use them in my write up for my analysis as the "top" in each category. How may I do this please
Another view of this data is as below. In this case the values appearing first that I have highlighted are the only ones that I want to access.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从您的帖子中重现数据:
以下是从
level = 0
中获取最大值的方法。Reproduce the data from your post:
Here's the approach that fetches the max value from
level=0
after you already sorteddf
in descending order.