Try this instead,

  print(
"{:.3f}% {} ({} sentences)".format(pcent, gender, nsents)
)

Refer the latest docs for more examples and check the Py version!

Answer from Aditya on Stack Exchange
🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-float-object-has-no-attribute
AttributeError: 'float' object has no attribute 'X' (Python) | bobbyhadz
The Python AttributeError: 'float' object has no attribute occurs when we try to access an attribute that doesn't exist on a floating-point number.
Discussions

I have a problem to check the range and type of the entry values using .get: "AttributeError: 'float' object has no attribute 'get'"
Hi, I expect that the below code build a GUI window and get three parameters from user, check the range of parameter 1 (which should be between 0 and 1), and handle any unacceptable value using a warning message box. However, if the entered value is out of range, the below error appears. More on discuss.python.org
🌐 discuss.python.org
7
0
September 21, 2023
python - AttributeError: 'float' object has no attribute 'get' - Stack Overflow
here is my error 2013-03-13 10:31:50,358 11345 ERROR OpenERP_DB openerp.osv.osv: Uncaught exception Traceback (most recent call last): File "/home/priyan/Software/openerp-7.0-20130309-002120/ope... More on stackoverflow.com
🌐 stackoverflow.com
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
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
🌐
GitHub
github.com › ultralytics › yolov5 › issues › 1049
AttributeError: 'float' object has no attribute 'round' · Issue #1049 · ultralytics/yolov5
September 26, 2020 - get error when training on custom data: File "train.py", line 459, in 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()) AttributeEr...
Author   universewill
Find elsewhere
🌐
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
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)
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-attributeerror-module-numpy-has-no-attribute-float-in-python
How to fix AttributeError: module numpy has no attribute float' in Python - GeeksforGeeks
July 23, 2025 - Using the built-in Python types directly means replacing the outdated numpy attribute (np.float) with the standard Python type (float). This solution ensures compatibility with recent numpy versions and avoids the "AttributeError: module 'numpy' has no attribute 'float'" error.
🌐
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. ... If I am using python EMS, then I don't have to define EnergyManagementSystem:Actuator in the IDF file manually.
Top answer
1 of 9
65

The answer is already provided in the comments by @mattdmo and @tdelaney:

  • NumPy 1.20 (release notes) deprecated numpy.float, numpy.int, and similar aliases, causing them to issue a deprecation warning

  • NumPy 1.24 (release notes) removed these aliases altogether, causing an error when they are used

In many cases you can simply replace the deprecated NumPy types by the equivalent Python built-in type, e.g., numpy.float becomes a "plain" Python float.

For detailed guidelines on how to deal with various deprecated types, have a closer look at the table and guideline in the release notes for 1.20:

...

To give a clear guideline for the vast majority of cases, for the types bool, object, str (and unicode) using the plain version is shorter and clear, and generally a good replacement. For float and complex you can use float64 and complex128 if you wish to be more explicit about the precision.

For np.int a direct replacement with np.int_ or int is also good and will not change behavior, but the precision will continue to depend on the computer and operating system. If you want to be more explicit and review the current use, you have the following alternatives:

  • np.int64 or np.int32 to specify the precision exactly. This ensures that results cannot depend on the computer or operating system.
  • np.int_ or int (the default), but be aware that it depends on the computer and operating system.
  • The C types: np.cint (int), np.int_ (long), np.longlong.
  • np.intp which is 32bit on 32bit machines 64bit on 64bit machines. This can be the best type to use for indexing.

...

If you have dependencies that use the deprecated types, a quick workaround would be to roll back your NumPy version to 1.24 or less (as suggested in some of the other answers), while waiting for the dependency to catch up. Alternatively, you could create a patch yourself and open a pull request, or monkey patch the dependency in your own code.

2 of 9
39

In the 1.24 version:

The deprecation for the aliases np.object, np.bool, np.float, np.complex, np.str, and np.int is expired (introduces NumPy 1.20). Some of these will now give a FutureWarning in addition to raising an error since they will be mapped to the NumPy scalars in the future.

pip install "numpy<1.24" to work around it.

In [1]: import numpy as np

In [2]: np.__version__
Out[2]: '1.23.5'

In [3]: np.float(3)
<ipython-input-3-8262e04d58e1>:1: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  np.float(3)
Out[3]: 3.0
🌐
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...
🌐
GitHub
github.com › vandijklab › cell2sentence › issues › 4
AttributeError: 'float' object has no attribute 'item' · Issue #4 · vandijklab/cell2sentence
October 12, 2024 - --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) [<ipython-input-29-808987c0b700>](https://localhost:8080/#) in <cell line: 1>() ----> 1 benchmark_expression_conversion( 2 benchmark_output_dir=output_path, 3 save_name=transformation_benchmarking_save_name, 4 normalized_expression_matrix=adata.X, 5 sample_size=1024, [/usr/local/lib/python3.10/dist-packages/cell2sentence/utils.py](https://localhost:8080/#) in benchmark_expression_conversion(benchmark_output_dir, save_name, normalized_expression_matrix, sample_size) 278 "
Author   ayyucedemirbas
🌐
PyTorch Forums
discuss.pytorch.org › autograd
AttributeError: 'float' object has no attribute 'dtype' when using extra arguments in jacrev() - autograd - PyTorch Forums
March 31, 2023 - Hi, I’m getting an error due to passing an argument (I think its the float k*r_trans) when using extra arguments to the function jacrev(). I tried declaring this as a tensor and then converting it back to a float inside …
🌐
Rssing
python1233.rssing.com › chan-44877200 › article18040.html
ItsMyCode: [Solved] AttributeError: ‘float’ object has no attribute ‘get’
The AttributeError: ‘float’ object has no attribute ‘get’ mainly occurs when you try to call the get() method on the float data type.
🌐
Brainly
brainly.com › computers and technology › high school › what is the block of code to solve this attributeerror: 'float' object has no attribute 'lower'?
[FREE] What is the block of code to solve this AttributeError: 'float' object has no attribute 'lower'? - brainly.com
November 19, 2023 - The AttributeError 'float object has no attribute lower' in Python is a result of trying to apply a method applicable only for strings onto a float. The lower() method is used in Python to convert all uppercase characters in a string to lowercase.
🌐
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 › scipy › scipy › issues › 17441
BUG: AttributeError: 'float' object has no attribute 'shape' · Issue #17441 · scipy/scipy
November 18, 2022 - Describe your issue. I tried to plot QQ plot by using stats.probplot, but raised AttributeError. Reproducing Code Example stats.probplot( df['col'], dist="norm", plot=pylab ) pylab.show() Error message AttributeError: 'float' object has ...
Author   bhaskoro-muthohar