我的代码-
data = data.replace("?", np.nan)
data = data.convert_objects(convert_numeric=True)
data.isnull().sum()
Run Code Online (Sandbox Code Playgroud)
错误-

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
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误?
小智 9
该方法X.convert_objects()似乎已被弃用。我可能会迟到回答这个问题,而且答案可能不完全正确,但是
X = X._convert(numeric=True)
Run Code Online (Sandbox Code Playgroud)
可能适合你。它对我有用。
您也可以查看,但在使用此功能时,我在执行( )convert_dtypes()等操作时遇到了问题。mean()Cannot perform reduction 'mean' with string dtype
| 归档时间: |
|
| 查看次数: |
8319 次 |
| 最近记录: |