If you pass a Series to apply, the (lambda) function receive a scalar (a float here). If you pass a DataFrame to apply, the (lambda) function receive a Series.

So you don't need apply here:

zscore_fun_improved(df.Close)

Demo:

# DataFrame -> apply get Series
>>> df.apply(type)
open     <class 'pandas.core.series.Series'>
close    <class 'pandas.core.series.Series'>
dtype: object

# Series -> apply get scalar values
>>> df['close'].apply(type)
0    <class 'float'>
1    <class 'float'>
2    <class 'float'>
3    <class 'float'>
4    <class 'float'>
Name: close, dtype: object
Answer from Corralien on Stack Overflow
🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-float-object-has-no-attribute
AttributeError: 'float' object has no attribute 'X' (Python) | bobbyhadz
Instead of accessing the round() function on the float, e.g.my_float.round(), we have to pass the floating point number as an argument to the round() function, e.g. round(3.5). If you need to check whether an object contains an attribute, use the hasattr function. ... Copied!example = 5.4 if hasattr(example, 'round'): print(example.round) else: print('Attribute is not present on object') # 👉️ This runs
Discussions

python - AttributeError: 'numpy.float64' object has no attribute 'rolling' - Stack Overflow
I would like to calculate the RSI figure once again in SMA and process it. However, an error similar to the subject occurs. " AttributeError: 'numpy.float64' object has no attribute 'rolling' " More on stackoverflow.com
🌐 stackoverflow.com
March 30, 2022
AttributeError: 'float' object has no attribute 'items'
on running celery -A proj worker throws this error [2018-11-15 12:02:53,607: CRITICAL/MainProcess] Unrecoverable error: AttributeError("'float' object has no attribute 'items'",) Traceback (most re... More on github.com
🌐 github.com
17
November 15, 2018
AttributeError: 'float' object has no attribute 'round'
There was an error while loading. Please reload this page · get error when training on custom data: More on github.com
🌐 github.com
5
September 26, 2020
python - Numpy AttributeError: 'float' object has no attribute 'exp' - Stack Overflow
this error message is very misleading: the problem is that the dtype is in fact numpy.object, but the message says numpy.float64 has no attribute log10, or whatever arithmetic method 2017-01-03T15:59:42.163Z+00:00 More on stackoverflow.com
🌐 stackoverflow.com
🌐
Stack Overflow
stackoverflow.com › questions › 71683727 › attributeerror-numpy-float64-object-has-no-attribute-rolling
python - AttributeError: 'numpy.float64' object has no attribute 'rolling' - Stack Overflow
March 30, 2022 - import talib import requests import pandas as pd import time class RSI: def rsi(symbol, timeinterval, limit, period): coin = Can.get_fu_coin(symbol, timeinterval, limit) coin['close'] = coin['close'].astype(float) data = coin['close'] period = period delta = data.diff() up, down = delta.copy(), delta.copy() up[up < 0] = 0 down[down > 0] = 0 _gain = up.ewm(com = (period - 1), min_periods = period).mean() _loss = down.abs().ewm(com = (period - 1), min_periods = period).mean() RS = _gain / _loss rsi = 100 - (100 / (1 + RS)) rsi = rsi.iloc[-1] rsi = round(rsi, 4) return rsi def rma(symbol, timeinterval, limit, period, n): data = RSI.rsi(symbol, timeinterval, limit, period).rolling(n) return talib.SMA(data,n) RSI.rma('BTCUSDT', '1m', '1000', 14, 7) ... RSI.rsi() clearly returns a float and the first line of rma calls .rolling on it, so the error seems straightforward and expected.
🌐
YouTube
youtube.com › watch
Resolving the 'float' object has no attribute 'rolling' Error in Python Pandas - YouTube
Learn how to fix the common error in Python Pandas when calculating Z-scores using a lambda function. This guide provides a clear explanation and a step-by-s...
Published   April 9, 2025
Views   0
🌐
GitHub
github.com › celery › celery › issues › 5175
AttributeError: 'float' object has no attribute 'items' · Issue #5175 · celery/celery
November 15, 2018 - on running celery -A proj worker throws this error [2018-11-15 12:02:53,607: CRITICAL/MainProcess] Unrecoverable error: AttributeError("'float' object has no attribute 'items'",) Traceback (most recent call last): File "/user/lib/python3...
Author   noufalvlpr
🌐
GitHub
github.com › ultralytics › yolov5 › issues › 1049
AttributeError: 'float' object has no attribute 'round' · Issue #1049 · ultralytics/yolov5
September 26, 2020 - File "train.py", line 459, in <module> train(hyp, opt, device, tb_writer) File "train.py", line 250, in train accumulate = max(1, np.interp(ni, xi, [1, nbs / total_batch_size]).round()) AttributeError: 'float' object has no attribute 'round' Reactions are currently unavailable ·
Author   universewill
Find elsewhere
🌐
DEV Community
dev.to › olakusibe › solving-attributeerror-float-object-has-no-attribute-rint-4la
Solving AttributeError: 'float' object has no attribute 'rint' - DEV Community
July 26, 2022 - import pandas as pd # an example of extracted data extracted_data = pd.DataFrame({ 'Brand': ['Gucci', 'Nike', 'Adidas', 'Hermes', 'Zara'], 'year_of_manufacture': [2010, 1999, '2012', 2011, '2008'], # mixed data type 'price': ['4034.203', 5000.00, '7450.17567', 3023.004, '4901.32345'] # mixed data type }) # cast specific columns to a desired data type cast_to_type = { 'year_of_manufacture': int, 'price': float } extracted_data = extracted_data.astype(cast_to_type) # do the transfrom extracted_data['price'] = extracted_data['price'].round(2) print(extracted_data)
🌐
Esri Community
community.esri.com › t5 › python-questions › attributeerror-float-object-has-no-attribute › td-p › 39532
Solved: AttributeError: 'float' object has no attribute 's... - Esri Community
December 12, 2021 - I'm hoping someone can tell me whats going on with the below bit of code. I keep getting the error AttributeError: 'float' object has no attribute 'setValue' and I'm not sure how to resolve it. Can someone please explain? NONFLOOD = "GRIDfield" NF1curs = arcpy.UpdateCursor(BuildingGridSe...
Top answer
1 of 3
26

The error points to this line:

df['content'] = df['content'].apply(lambda x: " ".join(x.lower() for x in x.split() \
                                    if x not in stop_words))

split is being used here as a method of Python's built-in str class. Your error indicates one or more values in df['content'] is of type float. This could be because there is a null value, i.e. NaN, or a non-null float value.

One workaround, which will stringify floats, is to just apply str on x before using split:

df['content'] = df['content'].apply(lambda x: " ".join(x.lower() for x in str(x).split() \
                                    if x not in stop_words))

Alternatively, and possibly a better solution, be explicit and use a named function with a try / except clause:

def converter(x):
    try:
        return ' '.join([x.lower() for x in str(x).split() if x not in stop_words])
    except AttributeError:
        return None  # or some other value

df['content'] = df['content'].apply(converter)

Since pd.Series.apply is just a loop with overhead, you may find a list comprehension or map more efficient:

df['content'] = [converter(x) for x in df['content']]
df['content'] = list(map(converter, df['content']))
2 of 3
9

split() is a python method which is only applicable to strings. It seems that your column "content" not only contains strings but also other values like floats to which you cannot apply the .split() mehthod.

Try converting the values to a string by using str(x).split() or by converting the entire column to strings first, which would be more efficient. You do this as follows:

df['column_name'].astype(str)
🌐
GitHub
github.com › nalepae › pandarallel › issues › 102
AttributeError: 'float' object has no attribute 'a' · Issue #102 · nalepae/pandarallel
July 22, 2020 - RemoteTraceback Traceback (most ... File "<ipython-input-4-ae12c3a75aca>", line 2, in func return math.sin(x.a**2) + math.sin(x.b**2) AttributeError: 'float' object has no attribute 'a' """ The above exception was the direct cause of the following exception: AttributeError ...
Author   mustafakhalidcs
🌐
freeCodeCamp
forum.freecodecamp.org › python
Bug found in Data Analysis Example B Lecture File - Python - The freeCodeCamp Forum
July 7, 2022 - In the Lecture_2.ipynb example code is: df['rental_gain_return'].mean().round(2) results in: AttributeError: 'float' object has no attribute 'round' This is incorrect and should be: round(df['rental_gain_return'].mean(),2) Same with the median as well. Version of python: 3.10.5 Version of pandas: 1.4.2-1
🌐
Unmet Hours
unmethours.com › question › 68535 › error-float-object-has-no-attribute-apply
Error: 'float' object has no attribute 'apply' - Unmet Hours
This variable is set a few lines above with the .get_actuator_handle method, which returns -1 if the object can't be found or one of the parameters (state, component_type, control_type, actuator_key) are set incorrectly. Have you initialized state = api.state_manager.new_state() before this? Otherwise "LIV1XWIN_SCH" may not be the correct schedule name.
🌐
GitHub
github.com › ranaroussi › yfinance › issues › 1096
AttributeError: 'float' object has no attribute 'upper' · Issue #1096 · ranaroussi/yfinance
October 19, 2022 - Any ideas on the error below? My code works fine on windows locally on my laptop, it basically pulls data for a group of 5000 stocks 1 by 1. When i try to run it onlinus most of the symbols work fine, but i seem to get this error a handf...
Author   gib-uk
🌐
GitHub
github.com › pandas-dev › pandas › issues › 2813
Rolling methods should support lists · Issue #2813 · pandas-dev/pandas
October 4, 2018 - >>> l = [1,2,3,4] >>> import numpy as np >>> np.cumsum(l) array([ 1, 3, 6, 10]) >>> import bottleneck as bn >>> bn.move_sum(l, 1) array([ 1., 2., 3., 4.]) >>> import pandas >>> pandas.rolling_sum(l, 1) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/site-packages/pandas-0.10.1-py2.7-linux-x86_64.egg/pandas/stats/moments.py", line 507, in f time_rule=time_rule, **kwargs) File "/usr/lib/python2.7/site-packages/pandas-0.10.1-py2.7-linux-x86_64.egg/pandas/stats/moments.py", line 281, in _rolling_moment return_hook, values = _process_data_structure(arg) File "/usr/lib/python2.7/site-packages/pandas-0.10.1-py2.7-linux-x86_64.egg/pandas/stats/moments.py", line 325, in _process_data_structure if not issubclass(values.dtype.type, float): AttributeError: 'list' object has no attribute 'dtype'