close

[Solved] AttributeError: ‘float’ object has no attribute ‘split’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error AttributeError: ‘float’ object has no attribute ‘split’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How AttributeError: ‘float’ object has no attribute ‘split’ Error Occurs?

Today I get the following error AttributeError: ‘float’ object has no attribute ‘split’ in python.

How To Solve AttributeError: ‘float’ object has no attribute ‘split’ Error ?

  1. How To Solve AttributeError: 'float' object has no attribute 'split' Error ?

    To Solve AttributeError: 'float' object has no attribute 'split' Error You might also use df = df.dropna(thresh=n) where n is the tolerance. Meaning, it requires n Non-NA values to not drop the row

  2. AttributeError: 'float' object has no attribute 'split'

    To Solve AttributeError: 'float' object has no attribute 'split' Error You might also use df = df.dropna(thresh=n) where n is the tolerance. Meaning, it requires n Non-NA values to not drop the row

Solution 1

You are right, such errors mostly caused by NaN representing empty cells. It is common to filter out such data, before applying your further operations, using this idiom on your dataframe df:

df_new = df[df['ColumnName'].notnull()]

Alternatively, it may be more handy to use fillna() method to impute (to replace) null values with something default. E.g. all null or NaN‘s can be replaced with the average value for its column

housing['LotArea'] = housing['LotArea'].fillna(housing.mean()['LotArea'])

or can be replaced with a value like empty string “” or another default value

housing['GarageCond']=housing['GarageCond'].fillna("")

Solution 2

You might also use df = df.dropna(thresh=n) where n is the tolerance. Meaning, it requires n Non-NA values to not drop the row

Mind you, this approach will remove the row

For example: If you have a dataframe with 5 columns, df.dropna(thresh=5) would drop any row that does not have 5 valid, or non-Na values.

In your case you might only want to keep valid rows; if so, you can set the threshold to the number of columns you have.

pandas documentation on dropna

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read