Attributeerror: ‘series’ object has no attribute ‘isnumeric’

AttributeError: ‘Series’ object has no attribute ‘isnumeric’

This error occurs when you try to call the isnumeric() method on a Pandas Series object, which doesn’t have the isnumeric() method.

The isnumeric() method is a built-in method in Python’s string class that checks whether a string is numeric or not.

Therefore, you can only call the isnumeric() method on a string object and not on a Pandas Series object.

Example:

Let’s say you have a Pandas Series object like this:

      
import pandas as pd

data = pd.Series(['123', '45', 'abc', '67'])
print(data.isnumeric())
      
    

This code will result in the AttributeError: 'Series' object has no attribute 'isnumeric' error because the isnumeric() method is called on a Pandas Series object instead of a string object.

To fix this error, you need to call the isnumeric() method on each element of the Series object individually. You can achieve this using the apply() method of the Series object. Here’s an updated example:

      
import pandas as pd

data = pd.Series(['123', '45', 'abc', '67'])
numeric_values = data.apply(lambda x: str(x).isnumeric())
print(numeric_values)
      
    

This code will print a new Series object indicating whether each element in the original Series is numeric or not.

Read more interesting post

Leave a comment