0

I am new to pandas. Here is my short description of dataset: enter image description here

When I am doing my df.info():

datasets=dataset.apply(pd.to_numeric,errors='coerce')
print(dataset.info())

    <class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 2192 entries, 2012-01-01 to 2017-12-31
Data columns (total 15 columns):
Temp_min                           2192 non-null int64
Temp_max                           2192 non-null int64
Temp_mean                          2192 non-null float64
humidity                           2192 non-null int64
wind                               2192 non-null int64
Rain                               2191 non-null float64
Latitude (*N)                      2192 non-null float64
Daytime_hour %                     2192 non-null float64
Soil                               0 non-null float64
Stage                              0 non-null float64
Kc                                 2182 non-null float64
ETo                                2192 non-null float64
ETcrop(mm/day)                     2182 non-null float64
PERC(mm/day)                       2192 non-null int64
Irrigation Requirement (mm/day)    2182 non-null float64
dtypes: float64(10), int64(5)
memory usage: 274.0 KB
None

But during running time:

evaluate_model(train, test, n_input);

I am getting error:

ValueError: could not convert string to float: 'Clay'

Please suggest me how to overcome this problem. Should I store "Clay" as some integer number like "0", "Sandy" as "1" to overcome above problem. If so, what string values not stored in dataset?. Please clarify my problem with any suitable approach. Thanks!!

Ratnesh
  • 1,554
  • 3
  • 12
  • 28
  • `convert_objects` is deprecated from 0.17. Use `to_numeric` with `errors='coerce'`, see the [linked duplicate](https://stackoverflow.com/questions/25952790/convert-pandas-series-from-dtype-object-to-float-and-errors-to-nans) – cs95 Apr 14 '19 at 19:00
  • @coldspeed, I am still getting the same error, I have edited the post after trying your above suggested method. Also, I am able to see the two different result i.e. on `df.info()` still showing the object while `df.apply(pd.to numeric)` showing nothing object. – Ratnesh Apr 14 '19 at 19:13
  • How do you expect to convert the word "Clay" to a float? – cs95 Apr 14 '19 at 19:14
  • @coldspeed, Yes, you are right, it can not be converted to float. But how I resolve the above error. Please suggest me. – Ratnesh Apr 14 '19 at 19:16
  • 1
    You have to assign the apply call back: `df = df.apply(pd.to_numeric,errors='coerce')` and make sure to rerun the code that creates `train` and `test` from modified `df`. – cs95 Apr 14 '19 at 19:17

0 Answers0