I think I understood what you wanted to do and what you did not understand (mainly about the way to modifiy objects with pandas). I assume that you wanted to:

  1. compute your aggregation by payment date in data
  2. and then set its index to 'Payment date' field

Short answer: if you want to have this result into data, simply execute:

data = data.groupby('Payment date ')['Payment amount'].sum().to_frame()

'Payment date ' will be your new index, to_frame prevents your single column resulting dataframe to be squeezed into a pandas Series (which I think was your first intention to avoid, resetting your index to then set it back).

Let's dive into your code.

First line

data = data.groupby('Payment Date ')

First line is ok, but might not do exactly what you want. You are taking data, which I assume is a pandas DataFrame and reaffect it a pandas DataFrameGroupBy object. This kind of object does not hold any data, you can see it simply as a mapping between index(s) of your original DataFrame and associated groups (here, payment dates).

Anyway, you got your groupby object into data.

Second line

data['Payment Amount '].sum().reset_index()

This line does nothing. It shows the result of the computation in your Jupyter notebook, but nothing has been changed in data. data is still the same DataFrameGroupBy object.

Third line

data = data.set_index('Payment Date ', inplace  = True)

An exception is raised, saying that a DataFrameGroupBy objet has no set_index method. This is because data has not been changed by your second line of code. Even so, I would encourage you to avoid using inplace=True anytime in your code. You should always go with explicit reassignements.

Your code could look like (if you don't like the short answer above):

data = data.groupby('Payment date ')
data = data['Payment amount'].sum().reset_index()
data = data.set_index('Payment date ')  # No inplace=True!
Answer from Pierre Massé on Stack Overflow
Top answer
1 of 1
5

I think I understood what you wanted to do and what you did not understand (mainly about the way to modifiy objects with pandas). I assume that you wanted to:

  1. compute your aggregation by payment date in data
  2. and then set its index to 'Payment date' field

Short answer: if you want to have this result into data, simply execute:

data = data.groupby('Payment date ')['Payment amount'].sum().to_frame()

'Payment date ' will be your new index, to_frame prevents your single column resulting dataframe to be squeezed into a pandas Series (which I think was your first intention to avoid, resetting your index to then set it back).

Let's dive into your code.

First line

data = data.groupby('Payment Date ')

First line is ok, but might not do exactly what you want. You are taking data, which I assume is a pandas DataFrame and reaffect it a pandas DataFrameGroupBy object. This kind of object does not hold any data, you can see it simply as a mapping between index(s) of your original DataFrame and associated groups (here, payment dates).

Anyway, you got your groupby object into data.

Second line

data['Payment Amount '].sum().reset_index()

This line does nothing. It shows the result of the computation in your Jupyter notebook, but nothing has been changed in data. data is still the same DataFrameGroupBy object.

Third line

data = data.set_index('Payment Date ', inplace  = True)

An exception is raised, saying that a DataFrameGroupBy objet has no set_index method. This is because data has not been changed by your second line of code. Even so, I would encourage you to avoid using inplace=True anytime in your code. You should always go with explicit reassignements.

Your code could look like (if you don't like the short answer above):

data = data.groupby('Payment date ')
data = data['Payment amount'].sum().reset_index()
data = data.set_index('Payment date ')  # No inplace=True!
🌐
Kaggle
kaggle.com › questions-and-answers › 511815
Convert DataFrameGroupBy object to a DataFrame
Click here if you are not automatically redirected after 5 seconds.
Discussions

python - DataFrameGroupBy' object has no attribute 'reset_index'? - Stack Overflow
I then created a df_new DataFrameGroupBy object to create a group of df based on 'hour' and 'dt'. Then I used the reset_index function on df_new but it is giving me the error: 'DataFrameGroupBy' object has no attribute 'reset_index'. I have tried to find a solution but I am stumped. More on stackoverflow.com
🌐 stackoverflow.com
BUG AttributeError: 'DataFrameGroupBy' object has no attribute '_obj_with_exclusions'
In [5]: df.groupby('a').mean() ...de_output_index(output, agg_labels) /home/nicolas/Git/pandas/pandas/core/groupby.py in __getattr__(self, attr) 557 558 raise AttributeError("%r object has no attribute %r" % --> 559 (type(self).__name__, attr)) 560 561 def __getitem__(self, key): AttributeError: 'DataFrameGroupBy' object has ... More on github.com
🌐 github.com
13
November 18, 2015
python 3.x - AttributeError: Cannot access callable attribute 'reset_index' of 'DataFrameGroupBy' objects, try using the 'apply' method - Stack Overflow
I get the following error ... callable attribute 'reset_index' of 'DataFrameGroupBy' objects, try using the 'apply' method. ... col1 | col2 | col3 | col4 | col5 ================================= A | A1 | A2 | A3 | DATE1 A | B1 | B2 | B3 | DATE2 ... This reduces the shape of my dataframe from (124,14) to (9,6). I want all the 124 rows. Can you please help? ... Sorry this is not an answer ... More on stackoverflow.com
🌐 stackoverflow.com
python - AttributeError: 'list' object has no attribute 'reset_index' - Stack Overflow
I keep getting the error: AttributeError: 'list' object has no attribute 'reset_index' ... But it was throwing a: Cannot access callable attribute 'groupby' of 'DataFrameGroupBy' objects, try using the 'apply' method More on stackoverflow.com
🌐 stackoverflow.com
🌐
Stack Overflow
stackoverflow.com › questions › 76699686 › dataframegroupby-object-has-no-attribute-reset-index
python - DataFrameGroupBy' object has no attribute 'reset_index'? - Stack Overflow
I'm voting to close since this hasn't been made clear. ... If you used groupby and then reset the index without any operation your output dataframe would be identical to your input dataframe.
🌐
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() ...de_output_index(output, agg_labels) /home/nicolas/Git/pandas/pandas/core/groupby.py in __getattr__(self, attr) 557 558 raise AttributeError("%r object has no attribute %r" % --> 559 (type(self).__name__, attr)) 560 561 def __getitem__(self, key): AttributeError: 'DataFrameGroupBy' object has ...
Author   nbonnotte
🌐
GitHub
gist.github.com › conormm › fd8b1980c28dd21cfaf6975c86c74d07
R to Python: Data wrangling with dplyr and pandas · GitHub
df.groupby('group1') df.groupby(['group1', 'group2']) df.reset_index() / or when grouping: df.groupby('group1', as_index=False)
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 56213580 › attributeerror-list-object-has-no-attribute-reset-index
python - AttributeError: 'list' object has no attribute 'reset_index' - Stack Overflow
I keep getting the error: AttributeError: 'list' object has no attribute 'reset_index' ... But it was throwing a: Cannot access callable attribute 'groupby' of 'DataFrameGroupBy' objects, try using the 'apply' method
🌐
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__
🌐
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
The problem is it not identifying the NEWS_SENTIMENT_DAILY_AVG column. Error message - AttributeError: 'DataFrameGroupBy' object has no attribute 'NEWS_SENTIMENT_DAILY_AVG' ... Reset_index works for index, not columns...
🌐
Reddit
reddit.com › r/learnpython › pandas set_index error with calplot
r/learnpython on Reddit: Pandas set_index error with calplot
March 28, 2023 -

I have a dataframe that I've moved down to two columns 'last date read' and 'read count'. I formatted it to %Y-%m and then grouped it using the dates and summed the total amount of books read.

I wanted to plot it using month_calplot from plotly_calplot but I get the following error and I'm not sure where to go from here:

Error:

line 247, in month_calplot
    gData = data.set_index(x)[y].groupby(Grouper(freq="M")).sum()
  File "C:\Python\Python310\lib\site-packages\pandas\core\generic.py", line 5575, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'set_index'

Code:

df2 = df2[['last date read', 'read count']]
df2['last date read'] = pd.to_datetime(df2['last date read'])
df2['last date read'] = df2['last date read'].dt.strftime('%Y-%m')

df2 = df2.groupby(['last date read'])['read count'].sum()

print(df2)
fig3 = month_calplot(
    df2,
    x='last date read',
    y='read count',
    colorscale="Purpor",
    showscale=True,
    total_height=250,
    dark_theme=True)
🌐
iO Flood
ioflood.com › blog › pandas-reset-index
Pandas Reset Index Methods | Built-in Functions Explained
July 22, 2024 - Remember, reset_index() is a method for pandas DataFrames, not for other data types. s = pd.Series(range(3)) try: s = s.reset_index() except AttributeError as e: print(e) # Output: # 'Series' object has no attribute 'reset_index'
🌐
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

🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-reset-index-after-groupby-pandas
How to reset index after Groupby pandas? - GeeksforGeeks
July 23, 2025 - reset_index() method restores the index of the grouped DataFrame to its default integer-based index, ensuring that the grouped column values are explicitly available as normal columns.
Top answer
1 of 5
2

"sklearn.datasets" is a scikit package, where it contains a method load_iris().

load_iris(), by default return an object which holds data, target and other members in it. In order to get actual values you have to read the data and target content itself.

Whereas 'iris.csv', holds feature and target together.

FYI: If you set return_X_y as True in load_iris(), then you will directly get features and target.

from sklearn import datasets
data,target = datasets.load_iris(return_X_y=True)
2 of 5
1

The Iris Dataset from Sklearn is in Sklearn's Bunch format:

print(type(iris))
print(iris.keys())

output:

<class 'sklearn.utils.Bunch'>
dict_keys(['data', 'target', 'target_names', 'DESCR', 'feature_names', 'filename'])

So, that's why you can access it as:

x=iris.data
y=iris.target

But when you read the CSV file as DataFrame as mentioned by you:

iris = pd.read_csv('iris.csv',header=None).iloc[:,2:4]
iris.head()

output is:

    2   3
0   petal_length    petal_width
1   1.4 0.2
2   1.4 0.2
3   1.3 0.2
4   1.5 0.2

Here the column names are '1' and '2'.

First of all you should read the CSV file as:

df = pd.read_csv('iris.csv')

you should not include header=None as your csv file includes the column names i.e. the headers.

So, now what you can do is something like this:

X = df.iloc[:, [2, 3]] # Will give you columns 2 and 3 i.e 'petal_length' and 'petal_width'
y = df.iloc[:, 4] # Label column i.e 'species'

or if you want to use the column names then:

X = df[['petal_length', 'petal_width']]
y = df.iloc['species']

Also, if you want to convert labels from string to numerical format use sklearn LabelEncoder

from sklearn import preprocessing
le = preprocessing.LabelEncoder()
y = le.fit_transform(y)
🌐
Dataquest Community
community.dataquest.io › q&a › dq courses
Using groupby function and agg function, also, sorting pivot tables using a dictionary - DQ Courses - Dataquest Community
October 31, 2022 - Screen Link: [Learn data science with Python and R projects](https://I-94 project, with some additional exploration) There’s more detail in the version saved on my own computer, including a later attempt to do some stuff with a pivot table. Here it is. I-94 project plus some exploration.ipynb (210.7 KB) My Code: traffic_by_day=(day.groupby(['day']))['day','traffic_volume'].agg({'day','sum'}) What I expected to happen: I expected this to produce the sum of traffic volume for each...
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.pandas › api › pyspark.pandas.DataFrame.reset_index.html
pyspark.pandas.DataFrame.reset_index — PySpark 4.1.1 documentation
If the index has multiple levels, we can reset a subset of them: >>> df.reset_index(level='class') class speed species max type name falcon bird 389.0 fly parrot bird 24.0 fly lion mammal 80.5 run monkey mammal NaN jump · If we are not dropping the index, by default, it is placed in the top level.