【发布时间】:2022-01-19 13:40:28
【问题描述】:
我有一个问题,我有这个 df:
**<class 'pandas.core.frame.DataFrame'>
RangeIndex: 44640 entries, 0 to 44639
Data columns (total 4 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 NOx_Min_[ppm] 44640 non-null object
1 NOx_Min_[mg/m3N] 44640 non-null object
2 NOx_corr_Min_[mg/m3N] 44640 non-null object
3 NOX 44640 non-null object
dtypes: object(4)
memory usage: 1.4+ MB
NOx_Min_[ppm] NOx_Min_[mg/m3N] NOx_corr_Min_[mg/m3N] NOX
0 0 0 0 MMC
1 0 0 0 MMC
2 0 0 0 MMC
3 0 0 0 MMC
4 0 0 0 MMC**
我正在尝试将对象转换为数字 gd['NOX']=pd.to_numeric(gd['NOX']) 然后通过我的神经网络对其进行处理,但它会生成以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
pandas/_libs/lib.pyx in pandas._libs.lib.maybe_convert_numeric()
ValueError: Unable to parse string "MMC"
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-11-78184c2df2b2> in <module>()
----> 1 gd['NOX']=pd.to_numeric(gd['NOX'])
/usr/local/lib/python3.7/dist-packages/pandas/core/tools/numeric.py in to_numeric(arg, errors, downcast)
151 try:
152 values = lib.maybe_convert_numeric(
--> 153 values, set(), coerce_numeric=coerce_numeric
154 )
155 except (ValueError, TypeError):
pandas/_libs/lib.pyx in pandas._libs.lib.maybe_convert_numeric()
ValueError: Unable to parse string "MMC" at position 0
我需要你的帮助
【问题讨论】:
标签: python pandas dataframe type-conversion