Pandas 中的 groupby -Python [英] groupby in Pandas -Python

查看:89
本文介绍了Pandas 中的 groupby -Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在我不理解的 groupby 对象中执行操作时收到错误消息.

I am getting an error message when I try to perform an operation in a groupby object which I do not understand.

对于可重现的示例,请考虑以下内容:

For a reproducible example consider the following:

import pandas as pd

species_plots_types



 record_id  plot_id plot_type   species_id
    0       1   2   Control NL
    2194    2   3   Long-term Krat Exclosure    NL
    1       3   2   Control DM
    4022    4   7   Rodent Exclosure    DM
    2195    5   3   Long-term Krat Exclosure    DM
    4838    6   1   Spectab exclosure   PF
    2       7   2   Control PE
    4839    8   1   Spectab exclosure   DM
    4840    9   1   Spectab exclosure   DM
    6833    10  6   Short-term Krat Exclosure   PF
    8415    11  5   Rodent Exclosure    DS
    4023    12  7   Rodent Exclosure    DM
    2196    13  3   Long-term Krat Exclosure    DM
    9609    14  8   Control DM
    6834    15  6   Short-term Krat Exclosure   DM

species_plots_types.groupby["plot_type"].size().to_frame()

TypeError: 'method' object is not subscriptable

species_plots_types.groupby["plot_type"].count()

TypeError: 'method' object is not subscriptable

您的建议将不胜感激.

推荐答案

使用括号:

species_plots_types.groupby("plot_type").count() 

代替方括号

species_plots_types.groupby["plot_type"].count()

参考给定的链接更多详情.

这篇关于Pandas 中的 groupby -Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆