ValueError: could not convert string to float: '' "
Question:
I am trying to convert the column-TRADE
in my CSV file to float values. They are presently of type string.
df.TRADES.astype(float)
which gives me an error:
ValueError: could not convert string to float: ”
I have attached my CSV file. Do I fill the empty cells with some data to mitigate this error?
Answers:
You have a string ''
in your TRADES
column. I suggest looking into the record with this value, but — if you’re certain that all values in TRADES
are correct as they are — you can use the pd.to_numeric
function to convert to float:
import pandas as pd
pd.to_numeric(df.TRADES, errors="ignore")
Values that cannot be parsed (i.e., ''
) will be set as NaN
.
I am trying to convert the column-TRADE
in my CSV file to float values. They are presently of type string.
df.TRADES.astype(float)
which gives me an error:
ValueError: could not convert string to float: ”
I have attached my CSV file. Do I fill the empty cells with some data to mitigate this error?
You have a string ''
in your TRADES
column. I suggest looking into the record with this value, but — if you’re certain that all values in TRADES
are correct as they are — you can use the pd.to_numeric
function to convert to float:
import pandas as pd
pd.to_numeric(df.TRADES, errors="ignore")
Values that cannot be parsed (i.e., ''
) will be set as NaN
.