Home > Enterprise >  df Objects to float
df Objects to float

Time:01-19

I have a problem I have this 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**

and I am trying to convert the objects to numbers gd['NOX']=pd.to_numeric(gd['NOX']) and then process it through my neural network but it generates the following error:


---------------------------------------------------------------------------
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

plz I need your help

CodePudding user response:

You can try:

gd['NOX'].apply(pd.to_numeric, args=('coerce',))

CodePudding user response:

The column "NOX" contains strings that are not convertible to float (strings that like "MMC"). However, the other columns could be converted to float and be used afterwards in your neural network.

  •  Tags:  
  • Related