账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    python 'SeriesGroupBy' object has no attribute quantile(0.1)
    80
    0
    R语言转成python. 求助R 语言如下SingleM <- data.frame(SingleM %>% group_by(Parameter,filename)%>% mutate(P10=quantile (Value, probs=0.1), P90=quantile (Value, probs=0.9), max=max(Value), min=min(Value)))Python 写成下面的不对SingleM = SingleM.groupby(['Par','Filename']).agg( P10=('Value','quantile(0.1)'), P90= ('Value', 'quantile(0.9)'), max = ('Value','max'), min = ('Value', 'min'))python 报错如下:AttributeError: 'SeriesGroupBy' object has no attribute 'quantile(.1)'SingleM = SingleM.groupby(['Par','Filename']).apply(lambda x: pd.DataFrame([[x.Value.quantile(0.1),x.Value.quantile(0.9),x.Value.max(),x.Value.min()]],columns=['P10','P90','max','min'])).reset_index()#P10=(quantile(Value,0.1)), P90= (np.quantile(Value,0.9)),第二种写法应该正确 但是如何去掉那个level 2 的列呢,试了reset_index() 好像也有问题df quantile API 如下:pandas.DataFrame.quantileDataFrame.quantile(q=0.5, axis=0, numeric_only=True, interpolation='linear')
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 一个人的旅行 普通会员 1楼

      The error message "SeriesGroupBy object has no attribute quantile(0.1)" occurs when you try to access the quantile attribute of a SeriesGroupBy object in Python, which is a built-in method in pandas library. The quantile method is used to compute the cumulative distribution function (CDF) of a given value in a pandas DataFrame or Series, and returns a Series object that represents the quantile values.

      If you are using a SeriesGroupBy object that was created using the GroupBy method or a pandas.core.groupby.GroupBy object, you can access the quantile attribute by specifying the value of quantile as an argument. For example: ```python import pandas as pd

      create a DataFrame with a GroupBy object

      df_grouped = pd.groupby(['x', 'y'], as_index=False)

      access the quantile of the first group by y (0.1)

      quantile_y_01 = df_grouped.quantile(0.1)

      print(quantile_y_01) ```

      If you are using a SeriesGroupBy object that was created using a DataFrameGroupBy object, you can access the quantile attribute by specifying the value of quantile as an argument: ```python import pandas as pd

      create a DataFrameGroupBy object with a DataFrame object

      df_grouped = pd.DataFrameGroupBy(df, on='x')

      access the quantile of the first group by y (0.1)

      quantile_y_01 = df_grouped.quantile(0.1)

      print(quantile_y_01) ```

      In both cases, the quantile attribute will return a Series object that contains the quantile values for the first group in the DataFrame or Series, based on the value of quantile specified. If the value of quantile is not a number, the quantile method will raise a ValueError exception. If you need to handle the case when the value of quantile is not a number, you can add a check before calling the quantile method: ```python import pandas as pd

      create a DataFrameGroupBy object with a DataFrame object

      df_grouped = pd.DataFrameGroupBy(df, on='x')

      check if the value of quantile is a number

      if isinstance(quantile, (int, float)): # access the quantile of the first group by y (0.1) quantile_y_01 = df_grouped.quantile(0.1) else: raise ValueError("Quantile value must be a number")

      print(quantile_y_01) ```

      This will raise a ValueError exception if the value of quantile is not a number, and the quantile method will return an empty Series object if it cannot be computed.

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部