Following the documentation for the pandas.DataFrame.groupby method, there are a couple ways you could fix this. The way I'd recommend is to explicitly specify the grouping column using the by parameter (although you don't need to), and then providing an aggregation function (looks like you want the mean). Any of these will work:

# Option 1
New.groupby(['P5PN']).mean()

# Option 2
New.groupby('P5PN').mean()

# Option 3
New.groupby(by=['P5PN']).mean()

The issue here is that while you are specifying a grouping column, you are not telling pandas how to aggregate the measures in the other columns of your data.

Note: you might want to update the title of your question to "'SeriesGroupBy' object has no attribute 'shape'" to match the actual error you're getting.

Answer from matsuninja on Stack Overflow
Discussions

python - AttributeError: 'DataFrame' object has no attribute 'group_by' - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
python - 'DataFrameGroupBy' object has no attribute 'to_frame' - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
Pandas AttributeError: 'DataFrame' object has no attribute 'group_by'

I mean, isn't it groupby(), not group_by()?

More on reddit.com
🌐 r/learnpython
3
3
February 28, 2018
Errors after deploying the app
Hi I created my first app using streamlit. It works without any errors in my own pc (Python 3.9.7) but when I deploy it on streamlit cloud (Python 3.9) I get this error: AttributeError: 'DataFrameGroupBy' object has no attribute 'value_counts' The line which this error refers to is: df_grouped ... More on discuss.streamlit.io
🌐 discuss.streamlit.io
1
1
March 2, 2022
🌐
GitHub
github.com › pandas-dev › pandas › issues › 11640
BUG AttributeError: 'DataFrameGroupBy' object has no attribute '_obj_with_exclusions' · Issue #11640 · pandas-dev/pandas
November 18, 2015 - In [5]: df.groupby('a').mean() --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-29-a830c6135818> in <module>() ----> 1 df.groupby('a').mean() /home/nicolas/Git/pandas/pandas/core/groupby.py in mean(self) 764 self._set_selection_from_grouper() 765 f = lambda x: x.mean(axis=self.axis) --> 766 return self._python_agg_general(f) 767 768 def median(self): /home/nicolas/Git/pandas/pandas/core/groupby.py in _python_agg_general(self, func, *args, **kwargs) 1245 output[name] = self._try_cast(values[mask], result)
Author   nbonnotte
🌐
Quora
quora.com › How-do-you-fix-pandas-that-have-no-attribute-dataframe
How to fix pandas that have no attribute dataframe - Quora
Answer (1 of 2): There are three possibilities here : * The filename could be pandas.py * The filename could be whatever you have imported as, for example, pd. You could have imported using import pandas as pd * There is another file with the name pandas.py or pd.py in the current directory W...
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 1.1 › reference › groupby.html
GroupBy — pandas 1.1.5 documentation
GroupBy objects are returned by groupby calls: pandas.DataFrame.groupby(), pandas.Series.groupby(), etc. The following methods are available in both SeriesGroupBy and DataFrameGroupBy objects, but may differ slightly, usually in that the DataFrameGroupBy version usually permits the specification of an axis argument, and often an argument indicating whether to restrict application to columns of a specific data type.
🌐
Databricks Community
community.databricks.com › t5 › data-engineering › attributeerror-dataframe-object-has-no-attribute › td-p › 61132
AttributeError: 'DataFrame' object has no attribut... - Databricks Community - 61132
February 19, 2024 - Hello, I have some trouble deduplicating rows on the "id" column, with the method "dropDuplicatesWithinWatermark" in a pipeline. When I run this pipeline, I get the error message: "AttributeError: 'DataFrame' object has no attribute 'dropDuplicatesWithinWatermark'" Here is part of the code: @dl...
🌐
CopyProgramming
copyprogramming.com › howto › error-attributeerror-dataframegroupby-object-has-no-attribute-while-groupby-functionality-on-dataframe
Python: DataFrameGroupBy Object Does Not Have Attribute Error Occurs When Using Groupby Functionality on DataFrame
April 22, 2023 - week_grouped = df.groupby('week') ... df function. ... The outcome of the program is an AttributeError that indicates the inability to reach the 'drop_duplicates' attribute of ' DataFrameGroupBy' object s....
Find elsewhere
🌐
Medium
paddyalton.medium.com › python-learnt-backwards-3482f52f0eb4
Python, learnt backwards. A tutorial for near-beginners | by Paddy Alton | Medium
December 22, 2022 - In the case of the linked question, the poster was confused because the DataFrame.groupby method doesn’t return a DataFrame object at all; it returns a DataFrameGroupBy object, a completely different class with different methods. Armed with the above details, the poster may deduce that they need to use one of those methods to convert back to a DataFrame … which does have a to_csv method. The right thing would then be to consult the documentation. Secondly, let’s examine this one — AttributeError: 'numpy.ndarray' object has no attribute 'append'.
🌐
Reddit
reddit.com › r/learnpython › pandas attributeerror: 'dataframe' object has no attribute 'group_by'
r/learnpython on Reddit: Pandas AttributeError: 'DataFrame' object has no attribute 'group_by'
February 28, 2018 -

Hello,

Has anyone ever come across this before?

I'm trying to group some data in a dataframe and getting this error. The steps I've taken are:

  1. in a for loop:

read in a csv from an api using pd.read_csv() replaced some values in a column using a for loop and .loc[] appended the resulting data frame to a list

2) concatenated the list of dataframes using pd.concat()

3) added a calculated column to the new DF by multiplying another column

4) added two empty columns

5) filtered the DF using .loc[] based on a value within a column

6) filtered the DF using .loc[] based on a value in a different column

7) tried to use this code:

new_DF = old_df.group_by(['col1', 'col_2', 'col_3', 'adgroup', 'col_4', 'col5', 'col6'], as_index=False)[['col7', 'col8', 
'col9']].sum()

The DF seems to behaving normally for example I can do dtypes and columns on it and add columns which are calculated from other columns. What is super frustrating is that I can do pd.to_csv() and then pd.read_csv() on the DF and then I'm able to do the grouping I want (however this isn't ideal which is why I'm posting).

Any advice would be appreciated.

Cheers

🌐
GitHub
github.com › nalepae › pandarallel › issues › 255
AttributeError: 'DataFrameGroupBy' object has no attribute 'parallel_apply' · Issue #255 · nalepae/pandarallel
November 11, 2023 - AttributeError: 'DataFrameGroupBy' object has no attribute 'parallel_apply' Write here the observed behavior
Author   beyondguo
🌐
Google Groups
groups.google.com › g › pydata › c › 4ZjOP0Lfjdc
Problem with groupby and nth in pandas 0.18.1
July 5, 2016 - I noticed that you can also have the original behaviour of 0.17 by passing as_index=False: In [13]: df.groupby('device', as_index=False)['timestamp'].nth(0) Out[13]: 0 0 3 1 Name: timestamp, dtype: int64 Are you sure the transform('idxmin') works? I get an error when I try that (both on 0.17.1 as 0.18.1): AttributeError: 'SeriesGroupBy' object has no attribute 'idxmim'
🌐
GitHub
github.com › pandas-dev › pandas › issues › 11558
groupby categorical column fails with unstack · Issue #11558 · pandas-dev/pandas
November 9, 2015 - Replicating example In [1]: df = pd.DataFrame([[1,2],[3,4]],columns=pd.CategoricalIndex(list('AB'))) In [2]: df.describe() AttributeError: 'DataFrame' object has no attribute 'value_counts' The behaviour in this notebook seems like a bug...
Author   mikepqr