Solution for SpecificationError: nested renamer is not supported while agg() along with groupby()

前端 未结 10 2179
有刺的猬
有刺的猬 2020-12-15 21:23
def stack_plot(data, xtick, col2=\'project_is_approved\', col3=\'total\'):
    ind = np.arange(data.shape[0])

    plt.figure(figsize=(20,5))
    p1 = plt.bar(ind, d         


        
相关标签:
10条回答
  • 2020-12-15 22:11

    This error also happens if a column specified in the aggregation function dict does not exist in the dataframe:

    In [190]: group = pd.DataFrame([[1, 2]], columns=['A', 'B']).groupby('A')
    In [195]: group.agg({'B': 'mean'})
    Out[195]: 
       B
    A   
    1  2
    
    In [196]: group.agg({'B': 'mean', 'non-existing-column': 'mean'})
    ...
    SpecificationError: nested renamer is not supported
    
    
    0 讨论(0)
  • 2020-12-15 22:11

    I have got the similar issue as @akshay jindal, but I check the documentation as suggested by @artikay Khanna, the problem solved, some functions has been adjusted, the old is deprecated. Here is the code warning provided per last time execute.

    /usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:1: FutureWarning: using a dict on a Series for aggregation
    is deprecated and will be removed in a future version. Use                 named aggregation instead.
    
        >>> grouper.agg(name_1=func_1, name_2=func_2)
    
      """Entry point for launching an IPython kernel.
    

    Therefore, I will suggest try

    grouper.agg(name_1=func_1, name_2=func_2)
    

    Hope this will help

    0 讨论(0)
  • 2020-12-15 22:20

    I found the way: Instead of going like

    g2 = df.groupby(["Description","CustomerID"],as_index=False).agg({'Quantity':{"maxQ":np.max,"minQ":np.min,"meanQ":np.mean}})
    g2.columns = ["Description","CustomerID","maxQ","minQ",'meanQ']
    

    Do as follows:

    g2 = df.groupby(["Description","CustomerID"],as_index=False).agg({'Quantity':{np.max,np.min,np.mean}})
    g2.columns = ["Description","CustomerID","maxQ","minQ",'meanQ']
    

    I had the same error and this is how I resolved it!

    0 讨论(0)
  • 2020-12-15 22:22

    I have tried alll the solutions and turned out to be the error with the name. If your column name has some inbuilt keywords such as "in", "is",etc., It is throwing error. In my case, My column name is "Points in Polygon" and I have resolved the issue by renaming the column to "Points"

    0 讨论(0)
提交回复
热议问题