DataFrame has no attribute group. However, it is possible to access data in a column in your dataframe with the same syntax used to access attributes and methods, i.e. if you have a column col, you may access the series related to this column through

df.col

What happened here is that your data is probably different from what she used in the tutorial. Or at least, the columns she has are different than the columns you have.

To solve that problem, you can either (I) simply rename your columns to match the columns from the tutorial or (II) replace data.group with the corresponding column name that you have in your df

Answer from rafaelc on Stack Overflow
🌐
Stack Overflow
stackoverflow.com › questions › 46534653 › error-attributeerror-dataframegroupby-object-has-no-attribute-while-groupby
python - Error 'AttributeError: 'DataFrameGroupBy' object has no attribute' while groupby functionality on dataframe - Stack Overflow
extract required columns from dataframe in news_count_res variable and then apply aggregation function · news_count_res = news_count[['year','month','NEWS_SENTIMENT_DAILY_AVG']] news_count_res.group(['year','month']).sum() ... Sign up to request clarification or add additional context in comments. ... Thanks for this...but I'm getting "AttributeError: 'SeriesGroupBy' object has no attribute 'sample'" at "df_sample = df.groupby("persons").sample(frac=percentage_to_flag, random_state=random_state)".
🌐
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
🌐
Reddit
reddit.com › r/learnpython › pandas groupby error in function only?
r/learnpython on Reddit: Pandas Groupby Error in Function Only?
March 11, 2020 -

I get the error " AttributeError: 'str' object has no attribute 'groupby' " when I run the following piece of code:

def groupby(df):

median_df = df.groupby('Brand').median()

return median_df

median_customer_df = groupby('customer_df')

However when outside of the function I simply run:

median_df = customer_df.groupby('Brand').median()

the code runs fine?

Can anyone please help explain why this groupby is failing only when in my function?

Thanks in advance!

🌐
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

🌐
Pandas
pandas.pydata.org › pandas-docs › version › 1.1 › reference › groupby.html
GroupBy — pandas 1.1.5 documentation
The following methods are available only for DataFrameGroupBy objects. pandas.api.indexers.VariableOffsetWindowIndexer.get_window_bounds pandas.core.groupby.GroupBy.__iter__
🌐
GitHub
github.com › dask › dask › issues › 2040
AttributeError: 'tuple' object has no attribute 'groupby · Issue #2040 · dask/dask
March 4, 2017 - --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-205-e8ff0304bc2c> in <module>() ----> 1 df.set_index("x", divisions=[0, 2, 5, 8, 10, 12, 14], sorted=True).groupby("y").count().compute() /path/to/python3.6/site-packages/dask/base.py in compute(self, **kwargs) 92 Extra keywords to forward to the scheduler ``get`` function.
Author   LostInOverflow
Find elsewhere
🌐
GitHub
github.com › nalepae › pandarallel › issues › 255
AttributeError: 'DataFrameGroupBy' object has no attribute 'parallel_apply' · Issue #255 · nalepae/pandarallel
November 11, 2023 - Python version: 3.8 · Pandas version: 2.0.3 · Pandarallel version: 1.6.5 · [ *] My issue is NOT present when using pandas without alone (without pandarallel) [ *] If I am on Windows, I read the Troubleshooting page before writing a new bug report · sentiment_df.groupby('scode').parallel_apply(lambda x: x['f'].rolling(window=window_size, min_periods=1).apply(func, raw=True)) AttributeError: 'DataFrameGroupBy' object has no attribute 'parallel_apply' Write here the observed behavior ·
Author   beyondguo
🌐
GitHub
github.com › pandas-dev › pandas › issues › 16174
DataFrame.groupby().std() fails on filtered DataFrame · Issue #16174 · pandas-dev/pandas
April 29, 2017 - dicts = [{'filter_col':False, 'groupby_col':True, 'bool_col':True, 'float_col':10.5}, {'filter_col':True, 'groupby_col':True, 'bool_col':True, 'float_col':20.5}, {'filter_col':True, 'groupby_col':True, 'bool_col':True, 'float_col':30.5}] df = DataFrame(dicts) df_filter = df[df['filter_col'] == True] dfgb = df_filter.groupby('groupby_col') dfgb.std() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python3.5/site-packages/pandas/core/groupby.py", line 1055, in std return np.sqrt(self.var(ddof=ddof)) AttributeError: 'bool' object has no attribute 'sqrt'
Author   edhalter
🌐
GitHub
github.com › pandas-dev › pandas › issues › 11562
'mode' not recognized by df.groupby().agg(), but pd.Series.mode works · Issue #11562 · pandas-dev/pandas
November 9, 2015 - df.groupby('B').agg('mode') ... AttributeError: Cannot access callable attribute 'mode' of 'DataFrameGroupBy' objects, try using the 'apply' method
Author   patricksurry
🌐
GitHub
github.com › dask › dask › issues › 3438
Dataframe groupby()[column].agg fails with AttributeError · Issue #3438 · dask/dask
April 24, 2018 - AttributeError Traceback (most recent call last) <ipython-input-1-b43466d1ae6a> in <module>() 6 -0.666]}) 7 ddf = dd.from_pandas(df, npartitions=1) ----> 8 ddf.groupby('A')['B'].agg('var') 9 10 ~/applications/anaconda3/lib/python3.6/site-packages/dask/dataframe/groupby.py in agg(self, arg, split_every, split_out) 1217 @derived_from(pd.core.groupby.SeriesGroupBy) 1218 def agg(self, arg, split_every=None, split_out=1): -> 1219 return self.aggregate(arg, split_every=split_every, split_out=split_out) ~/applications/anaconda3/lib/python3.6/site-packages/dask/dataframe/groupby.py in aggregate(self, arg, split_every, split_out) 1211 1212 if not isinstance(arg, (list, dict)): -> 1213 result = result[result.columns[0]] 1214 1215 return result AttributeError: 'Series' object has no attribute 'columns'
Author   joergdietrich
🌐
GitHub
github.com › pandas-dev › pandas › issues › 55041
BUG: groupby.agg fails when input has duplicate columns and dict input · Issue #55041 · pandas-dev/pandas
September 7, 2023 - df = DataFrame( [[1, 2, 3, 4], [1, 3, 4, 5], [2, 4, 5, 6]], columns=["a", "b", "c", "c"], ) gb = df.groupby("a") gb.agg({"c": "sum"}) raises AttributeError: 'DataFrame' object has no attribute 'name'. Did you mean: 'rename'? I would expe...
Author   rhshadrach
🌐
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'