When you use df.apply(), each row of your DataFrame will be passed to your lambda function as a pandas Series. The frame's columns will then be the index of the series and you can access values using series[label].

So this should work:

df['D'] = (df.apply(lambda x: myfunc(x[colNames[0]], x[colNames[1]]), axis=1)) 
Answer from foglerit on Stack Overflow
🌐
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)
🌐
GitHub
github.com › DeepSpace2 › StyleFrame › issues › 130
AttributeError: 'Series' object has no attribute 'style' · Issue #130 · DeepSpace2/StyleFrame
June 28, 2022 - #!/usr/bin/env python3 import os import sys import pathlib import pandas import styleframe import styleframe.utils print(styleframe._versions_) df = pandas.DataFrame( data={ 'idx1': list('AABB'), 'column with long caption': [1234, 345, 33123, 2], } ) df = df.set_index('idx1') print(df) file_path = pathlib.Path.cwd() / 'test.xlsx' default_style = styleframe.Styler(font_size=14) sf = styleframe.StyleFrame(df, styler_obj=default_style) sf.to_excel(file_path).save() os.system(str(file_path))
Author   buhtz
Discussions

AttributeError: 'Series' object has no attribute [X] when preparing DataBlock - Part 1 (2020) - fast.ai Course Forums
I am having trouble running some basic code. I have a DataFrame called papers with one column called abstracts, and I am trying to create a DataBlock to load it in a model. I prepare the data (in a Kaggle notebook with the Arxiv dataset) as a Dataframe as import json data_file = '../input/... More on forums.fast.ai
🌐 forums.fast.ai
0
December 13, 2020
python - Pandas - 'Series' object has no attribute - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Ask questions, find answers and collaborate at work with Stack Overflow for Teams More on stackoverflow.com
🌐 stackoverflow.com
AttributeError: 'Series' object has no attribute 'labelNames'
Hello. I have some matlab files containing some matrix (x1, x2,…) and a table (called labelNames). With the following code I’m trying to access to labelNames contained in the matlab files: Folder = 'dataCubes/' # Listing all .mat files contained in dataCubes folder; hence, put all mat # ... More on discuss.pytorch.org
🌐 discuss.pytorch.org
5
0
October 6, 2022
Python Pandas AttributeError: 'Series' object has no attribute 'columns' - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Ask questions, find answers and collaborate at work with Stack Overflow Internal More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › dask › dask › issues › 3681
'Series' object has no attribute 'columns' · Issue #3681 · dask/dask
June 28, 2018 - df = dd.read_parquet('/data/dask/af.pq',columns=['timestamp','gid','uid']) df.set_index('timestamp',inpalce=True) df.groupby('gid').apply(lambda x:x.resample('1D').uid.unique(),meta=('uid','object'))
Author   Cherrymelon
🌐
Fast.ai
forums.fast.ai › part 1 (2020)
AttributeError: 'Series' object has no attribute [X] when preparing DataBlock - Part 1 (2020) - fast.ai Course Forums
December 13, 2020 - I am having trouble running some basic code. I have a DataFrame called papers with one column called abstracts, and I am trying to create a DataBlock to load it in a model. I prepare the data (in a Kaggle notebook with the Arxiv dataset) as a Dataframe as import json data_file = '../input/arxiv/arxiv-metadata-oai-snapshot.json' def get_metadata(): with open(data_file, 'r') as f: for line in f: yield line metadata = get_metadata() titles = [] abstracts = ...
🌐
PyTorch Forums
discuss.pytorch.org › t › attributeerror-series-object-has-no-attribute-labelnames › 162952
AttributeError: 'Series' object has no attribute 'labelNames' - PyTorch Forums
October 6, 2022 - Hello. I have some matlab files containing some matrix (x1, x2,…) and a table (called labelNames). With the following code I’m trying to access to labelNames contained in the matlab files: Folder = 'dataCubes/' # Listing all .mat files contained in dataCubes folder; hence, put all mat # files in one folder without subfolders mat_files = glob(f'{Folder}/*.mat') numberOfDbExamples = len(mat_files) Data = {} for i in range(0, numberOfDbExamples): Data[i] = read_mat(mat_files[i]) Data.keys(...
🌐
Brainly
brainly.com › computers and technology › high school › how do you fix the error: "series' object has no attribute 'columns'"?
[FREE] How do you fix the error: "Series' object has no attribute 'columns'"? - brainly.com
November 19, 2023 - To fix this error, ensure you are calling attributes or methods appropriate for a Series, such as index or name, instead of attempting to access columns, which is an attribute specific to DataFrames.
Find elsewhere
🌐
Google Groups
groups.google.com › g › pyomo-forum › c › Org1bHNAds4
AttributeError: 'Series' object has no attribute 'is_expression_type'
Tg = self.params['Tg'].v() # ground temperature (T_out in equation 4)Also in order to set up the main model, we have: time_index = pd.DatetimeIndex(start=start_time, freq=str(time_step) + 'S', periods=n_steps) # Ground temperature t_g = pd.Series(12 + 273.15, index=t_amb.index)
🌐
GitHub
github.com › pycaret › pycaret › issues › 746
'Series' object has no attribute '_data' -- Loaded Model fails to predict when loaded on Windows but works on Linux · Issue #746 · pycaret/pycaret
October 21, 2020 - Unused 5823 """ -> 5824 return self.copy(deep=True) 5825 5826 def _convert( ~\Anaconda3\lib\site-packages\pandas\core\generic.py in copy(self, deep) 5809 dtype: object 5810 """ -> 5811 data = self._data.copy(deep=deep) 5812 return self._constructor(data).__finalize__(self) 5813 ~\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name) 5268 or name in self._accessors 5269 ): -> 5270 return object.__getattribute__(self, name) 5271 else: 5272 if self._info_axis._can_hold_identifiers_and_holds_name(name): AttributeError: 'Series' object has no attribute '_data'
Author   ealvarezj
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!
🌐
Reddit
reddit.com › r/learnpython › why am i suddenly getting "attributeerror: 'index' object has no attribute 'apply'"?
r/learnpython on Reddit: Why am I suddenly getting "AttributeError: 'Index' object has no attribute 'apply'"?
February 28, 2023 -

I don't understand... This exact code works for this same dataset look for different "X" variables, but now it is giving me this error...?

My code:

Import os Import pandas as pd

Os.chdir('file locations')

df = pd.read_csv('reading the file.csv') df = df.columns.str.replace(' ', '_')

def alphabet (row): If any(x in ['A', 'B', 'C'] for x in [row['alphanumeric_1'], row['alphanumeric_2]]): return 1 else: return 0

df['alphabet_yn] = df.apply(lambda row: alphabet (row), axis =1)

I don't understand why I am getting the AttributeError on the final line.

I am on my phone, so I apologize for how hard this might be to understand.

🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-attributeerror-object-has-no-attribute
How to fix AttributeError: object has no attribute - GeeksforGeeks
July 23, 2025 - To understand this error, we first have to know how to read the error message effectively. It typically consists of two parts: "AttributeError" and "Object has no attribute." The former indicates the type of error, and the latter suggests that the attribute we are trying to access does not exist for the object.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.reset_index.html
pandas.Series.reset_index — pandas 3.0.2 documentation
In either case, if inplace=True, no value is returned. ... Analogous function for DataFrame. ... >>> s = pd.Series( ... [1, 2, 3, 4], ... name="foo", ... index=pd.Index(["a", "b", "c", "d"], name="idx"), ... ) Generate a DataFrame with default index. >>> s.reset_index() idx foo 0 a 1 1 b 2 2 c 3 3 d 4 · To specify the name of the new column use name. >>> s.reset_index(name="values") idx values 0 a 1 1 b 2 2 c 3 3 d 4 · To generate a new Series with the default set drop to True.
🌐
GitHub
github.com › pandas-profiling › pandas-profiling › issues › 545
Profile generation failure - AttributeError: 'Series' object has ...
August 13, 2020 - Profile generation failure - AttributeError: 'Series' object has no attribute 'reshape'#545 · Copy link · justinsola · opened · on Aug 13, 2020 · Issue body actions · Describe the bug · I apologize if I am reporting poorly or misunderstanding the basics, I am inexperienced and this is my first bug report.
Author   justinsola
🌐
GitHub
github.com › slundberg › shap › issues › 944
AttributeError: 'Index' object has no attribute 'to_list' in function decision_plot · Issue #944 · shap/shap
December 12, 2019 - ~\AppData\Local\Continuum\anaconda3\lib\site-packages\shap\plots\decision.py in decision_plot(base_value, shap_values, features, feature_names, feature_order, feature_display_range, highlight, link, plot_color, axis_color, y_demarc_color, alpha, color_bar, auto_size_plot, title, xlim, show, return_objects, ignore_warnings, matplotlib) 323 elif str(type(features)) == "<class 'pandas.core.series.Series'>": 324 if feature_names is None: --> 325 feature_names = features.index.to_list() 326 features = features.values 327 elif isinstance(features, list): AttributeError: 'Index' object has no attribute 'to_list' Any help would be really appreciated.
Author   davidgar