Upgrade from Eikon -> Workspace. Learn about programming differences.

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
7 2 2 3

Trying to convert Total Return in a dataframe from Object type to float64 type. Not working.

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.

eikoneikon-data-apipythonrefinitiv-dataplatform-eikonworkspaceworkspace-data-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thank you for your participation in the forum. Is the reply below satisfactory in resolving your query? If yes please click the 'Accept' text next to the reply. This will guide all community members who have a similar question. Otherwise please post again offering further insight into your question. Thanks, AHS

Hello @DNKala

Thank you for your participation in the forum. Is the reply below satisfactory in resolving your query?

If so please can you click the 'Accept' text next to the appropriate reply. This will guide all community members who have a similar question.

Thanks,

AHS

1 Answer

· Write an Answer
Upvotes
Accepted
39.4k 77 11 27

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"])
>>> type(df['Total Return'][0])
<class 'numpy.float64'>
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.
What struck me in your depiction of your dataframe is that the index appears to start at 1 and not at 0. I cannot help but wonder how this happened and whether this is related to to_numeric method applied to 'Total Return' column returning "Unable to parse NaN at position 0".
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.