After importing using urlib
Internet data, I manage to create a DataFrame (df)
with two columns (Fecha y Valor)
of the types:
Fecha 1563 non-null object,
Valor 1563 non-null object.
With the statement df["Fecha"] = pd.to_datetime(df["Fecha"])
I get to pass the values of the column Fecha
, to the formatFecha 1563 non-null datetime64[ns]
Next I try to change the format of the column valor
with the statement df["Valor"] = pd.to_numeric(df["Valor"])
and I get the error:
ValueError: Unable to parse string "185,130000" at position 0.
I try again with the statement df['Valor'] = df['Valor'].apply(np.float)
and it gives me the error:
ValueError: Unable to parse string "185,130000" at position 0
What else could I do?
The problem apparently is the format of the string: the value
185,130000
cannot be converted to any numeric value because it cannot interpret the,
as a decimal separator. A possible solution is to replace this character with the.
:On the other hand, if you are reading this data from a file
csv
usingread_csv
, you may want to set the comma (,
) as the decimal separator at that time, using the parameterdecimal=','
.