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
Discussions

'float' object has no attribute...(beginner)
Hello there, I have written a simple function to find the area of a square: def area_of_square(): side_length = float(raw_input("Length in cm: ")) area = side_length ** 2 if side_length.isalpha(): print “this is not a number” else: print area When I attempt to run this, after I input the ... More on discuss.codecademy.com
🌐 discuss.codecademy.com
1
0
August 14, 2020
python - 'float' object has no attribute 'astype' - Stack Overflow
The median value that I am getting ... integer format. c_med = round(df['count'].median().astype(int)) c_med = round(df['count'].median()).astype(int) Both the above types give me this error. If astype(int) is removed then the answer is correct. ... Traceback (most recent call last): File "all_median.py", line 16, in c_med = round(df['count'].median()).astype(int) AttributeError: 'float' object has no attribute ... More on stackoverflow.com
🌐 stackoverflow.com
AttributeError: 'float' object has no attribute 'round'
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()) AttributeError: 'float' object has no attribute 'round' More on github.com
🌐 github.com
5
September 26, 2020
AttributeError: 'float' object has no attribute 'value_in_unit' (and others)
Right now CI is failing due to the new openff toolkit using a different package for units. The openff-unit package provides a way to support both using openmm.units and openff.units. For now in PR #129 I will just pin to the older toolki... More on github.com
🌐 github.com
9
September 26, 2022
🌐
GitHub
github.com › ranaroussi › yfinance › issues › 1096
AttributeError: 'float' object has no attribute 'upper' · Issue #1096 · ranaroussi/yfinance
October 19, 2022 - Exception in thread Thread-1337: ... "/usr/local/lib/python3.8/dist-packages/pytz/init.py", line 170, in timezone if zone.upper() == 'UTC': AttributeError: 'float' object has no attribute 'upper'...
Author   gib-uk
🌐
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.
🌐
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
🌐
Researchdatapod
researchdatapod.com › home › how to solve python attributeerror: ‘float’ object has no attribute ’round’
How to Solve Python AttributeError: 'float' object has no attribute 'round' - The Research Scientist Pod
September 25, 2024 - Congratulations on reading to the end of this tutorial! The AttributeError ‘float’ object has no attribute ’round’ occurs when you incorrectly call the round() function on a floating-point number.
Find elsewhere
🌐
GitHub
github.com › choderalab › espaloma › issues › 130
AttributeError: 'float' object has no attribute 'value_in_unit' (and others) · Issue #130 · choderalab/espaloma
September 26, 2022 - Right now CI is failing due to the new openff toolkit using a different package for units. The openff-unit package provides a way to support both using openmm.units and openff.units. For now in PR #129 I will just pin to the older toolki...
Author   mikemhenry
🌐
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.
🌐
Rssing
python1233.rssing.com › chan-44877200 › article18040.html
ItsMyCode: [Solved] AttributeError: ‘float’ object has no attribute ‘get’
If we call the get() method on the float data type, Python will raise an AttributeError: ‘float’ object has no attribute ‘get’. The error can also happen if you have a method which returns an float instead of a dictionary.
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 › Esri › arcgis-python-api › issues › 1068
to_featurelayer method fails with "AttributeError: 'float' object has no attribute 'type'" when row has null geometry · Issue #1068 · Esri/arcgis-python-api
July 26, 2021 - The issue is with the arcgis.features.SpatialDataFrame.to_featurelayer method. As written, it does not properly handle the occurance of null geometry values in a row. Example Traceback: AttributeEr...
Author   earlmedina
🌐
GitHub
github.com › vandijklab › cell2sentence › issues › 4
AttributeError: 'float' object has no attribute 'item' · Issue #4 · vandijklab/cell2sentence
October 12, 2024 - ------------------------------... normalized_expression_matrix, sample_size) 278 "slope": [linear_reg.coef_.item()], 279 "intercept": [linear_reg.intercept_.item()], --> 280 "r_squared": [r_squared_score.item()], 281 "pearson_r_statistic": [pearson_r_score.statistic.item()], 282 "pearson_r_pvalue": [pearson_r_score.pvalue.item()], AttributeError: 'float' object has no attribute ...
Author   ayyucedemirbas
🌐
Google Groups
groups.google.com › g › fuma-gwas-users › c › JlE4XjSwd3w
AttributeError: 'float' object has no attribute 'replace')
February 2, 2021 - Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message ... The issue you seem to be facing is that one of the columns that should have a number instead contains a different data format.
🌐
PyTorch Forums
discuss.pytorch.org › distributed
AttributeError: 'float' object has no attribute 'device' - distributed - PyTorch Forums
October 24, 2022 - Hi, I’m running in this error after 9 epochs of multi-GPU training using DataParallel. Any idea what’s going on? output = self.net(data) File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl ...
🌐
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 - The "AttributeError: module 'numpy' has no attribute 'float'" means that the codebase is unable to find the 'float' datatype in the NumPy module. It occurs because recent versions of numpy have deprecated and removed the float attribute.
🌐
GitHub
github.com › google › adk-python › issues › 1031
Adk evaluation failing with: "AttributeError: 'float' object has no attribute 'item'" · Issue #1031 · google/adk-python
May 29, 2025 - ... None [1 rows x 6 columns], metadata=None) def _get_score(self, eval_result) -> float: > return eval_result.summary_metrics[f"{self._metric_name}/mean"].item() E AttributeError: 'float' object has no attribute 'item' ..\.env\Lib\site-packages\google\adk\evaluation\response_evaluator.py:120: AttributeError
Published   May 29, 2025
Author   iperdomocabrera