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
- Missing ‘=’ operator after key in hash literal.
- Module jdk.compiler does not “opens com.sun.tools.javac.processing”
- The body might complete normally, causing ‘null’ to be returned, but the return type, ‘widget’, is a potentially non-nullable type. try adding either a return or a throw statement at the end.
- Attributeerror: ‘pyqt5.qtcore.pyqtsignal’ object has no attribute ‘connect’