2

My code-

data = data.replace("?", np.nan)
data = data.convert_objects(convert_numeric=True)

data.isnull().sum()

ERROR-

enter image description here

AttributeError                            Traceback (most recent call last)
<ipython-input-7-1cfce90286bb> in <module>()
      2 
      3 data = data.replace("?", np.nan)
----> 4 data = data.convert_objects(convert_numeric=True)
      5 
      6 data.isnull().sum()

/usr/local/lib/python3.7/dist-packages/pandas/core/generic.py in __getattr__(self, name)
   5139             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5140                 return self[name]
-> 5141             return object.__getattribute__(self, name)
   5142 
   5143     def __setattr__(self, name: str, value) -> None:

AttributeError: 'DataFrame' object has no attribute 'convert_objects

How can I solve this error?

1

1 Answer 1

9

The method X.convert_objects() seems to have been deprecated. I might be late to answer this, and the answer might not be entirely correct, but

X = X._convert(numeric=True)

might work for you. It did for me.

You could also check out convert_dtypes() but upon using this I ran into issues while performing operations like mean() (Cannot perform reduction 'mean' with string dtype).

Sign up to request clarification or add additional context in comments.

1 Comment

Do you know why it was deprecated? :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.