Fastest way to pull API data to existing DataFrame (using nonhemogenous SDate)

Brent
Brent Newcomer
edited December 2024 in Eikon Data APIs

Very curious to learn if there is a better (faster) way to pull API data on an existing df when the 'SDate' varies by row.

I'm new to programming, so I've only figured out how to do this using a for loop.

Is there a better (faster) way to do this?

Example code below:

[1] import refinitiv.data as rd

[2] import pandas as pd

[3] rd.open_session()

[4] temp = [ ]
for row in df.iterrows():
x = rd.get_data(
universe = row[1][0],
fields = ['TR.PriceClose',
'TR.DPSActValue'],
parameters = {
'SDate': row[1][9],
}
)
temp.append(x)

Many thanks!

Answers

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @Brent

    Thank you for reaching out to us.

    The SDate parameter is associated with fields so you can do something like this:

    x = rd.get_data(
        universe = ["IBM.N","LSEG.L"],
        fields = [
            'TR.PriceClose(SDate=2024-12-18)',
            'TR.DPSActValue(SDate=2024-12-18)',
            'TR.PriceClose(SDate=2024-12-19)',
            'TR.DPSActValue(SDate=2024-12-19)',
            'TR.PriceClose(SDate=2024-12-20)',
            'TR.DPSActValue(SDate=2024-12-20)',
            'TR.PriceClose(SDate=2024-12-23)',
            'TR.DPSActValue(SDate=2024-12-23)'
        ],
        use_field_names_in_headers=True
        
    )
    x
    

    The output is:

    image.png

    Otherwise, you need to use separated method calls.