I have a dataframe TSRdfr which I have accessed from Eikon API on Python.
Index Instrument Total Return
1. RIO.L. 15.990065
2. AAP.A. 22.543209
and so on ....
The data type of Total Return is Object which I need to convert to float64. I am using the syntax below.
TSRdfr["Total Return"] = pd.to_numeric(TSRdfr["Total Return"], errors='coerce')
This is not converting the data type of Return from Object to float64. I tried removing errors ='coerce' to see what's happening.
I am getting an error saying: "Unable to parse NaN at position 0"
The Return numbers are accessed from Refinitiv Eikon API. I am assuming they are too large to convert to float64. Any suggestions??
I know this question is not specific to Eikon API, but some help will be appreciated.
It's hard to say what's going on without having a copy of the dataframe or knowing exactly how it was created. Your assumption that the total return number is too large is definitely incorrect. Numeric data is returned by Eikon Data APIs as float64. Here's an example.
>>> df, err = ek.get_data(["RIO.L","AAP.A"],["TR.TotalReturn"])More specifically, when get_data method constructs the dataframe and populates it with the values extracted from JSON retrieved from the Web service delivering the data, the method applies pandas to_numeric function to each column of the dataframe before returning the result. If your dataframe is constructed using get_data method there's no point in applying to_numeric function again.
>>> type(df['Total Return'][0])
<class 'numpy.float64'>