There is string 'pct', need variable pct - lambda function by removing '':

aggs = {'B':pct}
print(df.groupby('A').agg(aggs))

          B
A          
1  0.333333
4  0.333333
7  0.333333
Answer from jezrael on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.groupby.html
pandas.Series.groupby — pandas 3.0.2 documentation
If a list or ndarray of length equal to the selected axis is passed (see the groupby user guide), the values are used as-is to determine the groups. A label or list of labels may be passed to group by the columns in self. Notice that a tuple is interpreted as a (single) key. levelint, level name, or sequence of such, default None · If the axis is a MultiIndex (hierarchical), group by a particular level or levels. Do not specify both by and level. ... Return object with group labels as the index.
Discussions

'mode' not recognized by df.groupby().agg(), but pd.Series.mode works
There was an error while loading. Please reload this page · I thought all the series aggregate methods propagated automatically to groupby, but I've probably misunderstood More on github.com
🌐 github.com
7
November 9, 2015
AttributeError: SeriesGroupBy object has no attribute ffill
Hi, I’m trying to convert some pandas code into Dask. In pandas, I can easily ffill my SeriesGroupBy object, toy example: import numpy as np import pandas as pd df = pd.DataFrame({ 'a_cat': list('aabbbaccc'), 'b_num': [np.nan if i%3!=0 else (i+1) for i in range(9)] }) df.groupby('a_cat')... More on dask.discourse.group
🌐 dask.discourse.group
3
0
February 10, 2022
python - Error 'AttributeError: 'DataFrameGroupBy' object has no attribute' while groupby functionality on dataframe - 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 3.x - In pandas, why I am getting error like "'SeriesGroupBy' object has no attribute 'Mean' - Stack Overflow
I have a dataframe with 2 columns and I am applying 'groupby' as per one column. Now I want to get the aggregate value for 'Sum', "Maximum' and "Minimum" using: df.groupby(["Col... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › dask › dask › issues › 4307
SeriesGroupBy Object has not Attribute Diff · Issue #4307 · dask/dask
December 17, 2018 - df.groupby('IndexName')['ColName'].diff() ..'SeriesGroupBy' object has no attribute 'diff · The Dask Series object has a diff method, as does the pandas series groupby object, and it seems logical that the dask SeriesGroupBy object would as well. I've tried the following work around: MyDiff = df.groupby('IndexName')['ColName'].apply( lambda x : x.diff(1) ); "but that give me a wrong number of items passed 0..." error.
Author   bgoodman44
🌐
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 - This works: df = pd.DataFrame({'A': [1, 2, 1, 2, 1, 2, 3], 'B': [1, 1, 1, 2, 2, 2, 2]}) df.groupby('B').agg(pd.Series.mode) but this doesn't: df.groupby('B').agg('mode') ... AttributeError: Cannot access callable attribute 'mode' of 'Dat...
Author   patricksurry
🌐
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
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)". If I can figure out why, maybe it'll work for me...
🌐
GitHub
github.com › pandas-dev › pandas › issues › 40139
ENH:AttributeError: 'SeriesGroupBy' object has no attribute 'kurtosis' · Issue #40139 · pandas-dev/pandas
March 1, 2021 - df = pd.DataFrame({'birb':['Falcon', 'Falcon', 'Falcon', 'Falcon', 'Parrot', 'Parrot', 'Parrot', 'Parrot'], 'value': [390., 350.,390., 350., 30., 20., 30., 20.]}) df.groupby('birb').aggregate({'value': ['count', 'mean', 'skew']}) Code gives error: AttributeError: 'SeriesGroupBy' object has no attribute 'kurtosis' instead of correct group-wise kurtosis.
Author   rsuhada
Find elsewhere
🌐
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' Whoops, there was a typo in your code, which is the cause that it failed: idxmim of course does not work, but idxmin does :-)  ·
🌐
GitHub
github.com › pandas-dev › pandas › issues › 15082
Unclear ValueError on core.groupby · Issue #15082 · pandas-dev/pandas
def test_groupby_aggregate_item_by_item(self): def test_df(): s = pd.DataFrame(np.array([[13, 14, 15, 16]]), index=[0], columns=['b', 'c', 'd', 'e']) num = np.array([[s, s, s, datetime.strptime('2016-12-28', "%Y-%m-%d"), 'asdf', 24], [s, s, s, datetime.strptime('2016-12-28', "%Y-%m-%d"), 'asdf', 6]]) columns = ['a', 'b', 'c', 'd', 'e', 'f'] idx = [x for x in xrange(0, len(num))] return pd.DataFrame(num, index=idx, columns=columns) c = [test_df().sort_values(['d', 'e', 'f']), test_df().sort_values(['d', 'e', 'f'])] df = pd.concat(c) df = df[["e", "a"]].copy().reset_index(drop=True) df["e_idx"] = df["e"] what = [0, 0.5, 0.5, 1] def x(): df.groupby(["e_idx", "e"])["a"].quantile(what) self.assertRaisesRegexp(ValueError, "'SeriesGroupBy' object has no attribute '_aggregate_item_by_item'", x)
Author   ghost
🌐
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 SeriesGroupBy objects. The following methods are available only for DataFrameGroupBy objects. pandas.api.indexers.VariableOffsetWindowIndexer.get_window_bounds pandas.core.groupby.GroupBy.__iter__
🌐
Reddit
reddit.com › r/learnpython › using isin() on grouped data
r/learnpython on Reddit: Using isin() on grouped data
December 1, 2021 -

Hi,

I want to filter based on whether a value is in another column. However this data needs to be grouped before the isin filter in applied. When I do this I get the error

'SeriesGroupBy' object has no attribute 'isin'

Example explaining what I'm trying to do:

 import pandas as pd

dict = {'AttributeName': {0: 'John', 1: 'John', 2: 'John', 3: 'John', 4: 'Sally', 5: 'Sally'}, 'Lineage Step': {0: 1, 1: 2, 2: 3, 3: 4, 4:1, 5:2}, 'From Country': {0: 'Spain', 1: 'Scotland', 2: 'England', 3: 'England', 4: 'Scotland', 5:'England'}, 'From Town': {0: 'Madrid', 1: 'Edinburgh', 2: 'London', 3: 'London', 4: 'Edinburgh', 5: 'Manchester'}, 'FromStreet': {0: 'Spanish St', 1: 'Main St', 2: 'Lower St', 3: 'Middle St', 4: 'London St', 5: 'Scotland St'}, 'ToCountry': {0: 'Scotland', 1: 'England', 2: 'England', 3: 'England', 4: 'England', 5: 'England'}, 'ToTown': {0: 'Edinburgh', 1: 'London', 2: 'London', 3: 'London', 4: 'Liverpool', 5: 'London'}, 'ToStreet': {0: 'Lower St', 1: 'Middle St', 2: 'Upper St', 3: 'Upper St', 4: 'new St', 5: 'Old St'}}
sample_data = pd.DataFrame.from_dict(dict)

#example data set. I want to find every unique 'fromCountry' for both John and Sally. So For John we would just have the first row, where he enters from Spain to Scotland. The second row would be filtered as Scotland appears in the 'ToCountry' column. Sally would just have the 'FromCountry' Edinburgh row. 

I have tried to do like this:

sample_grouped = sample_data.groupby('AttributeName')
sample_grouped[~sample_grouped['From Country'].isin(sample_grouped['ToCountry'])]

but I get there error 'SeriesGroupBy' object has no attribute 'isin'

Does anyone know how to use the isin (or comparable) function on grouped by data?

Thanks

🌐
GitHub
github.com › pandas-dev › pandas › issues › 32293
ENH: implement SeriesGroupBy.corrwith · Issue #32293 · pandas-dev/pandas
February 27, 2020 - >>> df.groupby('key') <pandas.core.groupby.generic.DataFrameGroupBy object at 0x000001C0D32FC400> # DataFrameGroupBy.corrwith has no issues >>> df.groupby('key').corrwith(pd.Series([1,2,3,1,2,3])) value key a 1.0 b -1.0 >>> df.groupby('key')['value'] <pandas.core.groupby.generic.SeriesGroupBy object at 0x000001C0D279BF28> # SeriesGroupBy.corrwith is not implemented >>> df.groupby('key')['value'].corrwith(pd.Series([1, 2, 3, 1, 2, 3])) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "c:\users\xxx\xxx\pandas\pandas\core\groupby\groupby.py", line 580, in __getattr__ f"'{type(self).__name__}' object has no attribute '{attr}'" AttributeError: 'SeriesGroupBy' object has no attribute 'corrwith' As shown above, DataFrameGroupBy.corrwith has no issues and works as expected.
Author   fujiaxiang
🌐
GitHub
github.com › pandas-dev › pandas › issues › 49907
BUG: SeriesGroupBy.apply sets name attribute if result is DataFrame · Issue #49907 · pandas-dev/pandas
November 25, 2022 - I have confirmed this bug exists on the main branch of pandas. def f(piece): return DataFrame({"value": piece, "demeaned": piece - piece.mean()}) df = pd.DataFrame({'a': [1,2,3], 'b': [4, 5, 5]}) res = df.groupby('a')['b'].apply(f) print(res.name) This prints 'b'. But .name shouldn't be an attribute of DataFrame... AttributeError: 'DataFrame' object has no attribute 'name'
Author   MarcoGorelli
🌐
Reddit
reddit.com › r/dataanalysis › data analysis in python
r/dataanalysis on Reddit: Data Analysis in Python
December 19, 2022 -

Hello everyone!
I am a newbie at python and I looked up some problems associated with the Data Expo 2009: Airline on time data from the Harvard Dataverse (https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/HG7NV7).
I am currently working on the following question:

  1. When is the best time of day, day of the week, and time of year to fly to minimize delays?

All libraries are imported and the data is cleared up (empty columns and duplicate rows are dropped).
What I was intending to do is to plot a bar chart with "Months" on the x-axis and "ArrDelay" (arrival delays) on the y-axis.

My code looks the following way (I'm using jupyter notebook):

import pandas as pd 
dataair = pd.read_csv("/Users/issakovakamilla/Desktop/2000.csv.bz2")
dataair.dropna(how='all', axis=1, inplace=True)
dataair
import matplotlib.pyplot as plt
df = pd.DataFrame(dataair)
X = list(df.iloc[:, 0])
Y = list(df.iloc[:, 1])
plt.bar(X, Y, color='g')
plt.title("stats")
plt.xlabel("Month")
plt.ylabel("ArrDelay")
plt.show()

Somehow I don't get a plot - its been executing for 10 minutes now (I get * near input). Could anyone help me with this?

🌐
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

🌐
Aimee
aimee.codes › blog › 2020 › 11 › 11 › filling-NA-values
Filling Categorical NAs
November 11, 2020 - One issue is that there is not a .mode() we can use at the end of our statement - this groupby function only works with numerical summaries, like mean, variance, or median. So we need to find a work-around, since our data is categorical and we’re assigning it based on the Neighborhood's mode. grouped['SalePrice'].mode() AttributeError: 'SeriesGroupBy' object has no attribute 'mode'