question

Upvotes
Accepted
16 1 1 9

Handling Screener errors in a for loop

Hello! When using the Python api to loop through criteria to screen for companies, the api is kicking out errors in some passes. Do you have any advice on how to store these errors and/or supress/skip over them to speed the loop up? Below is the code. The error arises because for some countries and industry code combinations, zero companies come out of the screener. Thanks a lot for your help.

import refinitiv.data as rd
rd.open_session()

import pandas as pd

indcode = [52, 53, 54, 57]
region = ["ES","AD","SM"]
syntax = "SCREEN(U(IN(Equity(active,public,primary))), CURN=USD"
CATfields = ["TR.CommonName", "TR.HeadquartersCountry", "TR.HQCountryCode"]

dataCAT2 = []
for i in region:
    for j in indcode:
        dataCAT1 = rd.get_data(syntax + f", IN(TR.TRBCEconSectorCode,{j}), IN(TR.HQCountryCode,{i}))", CATfields)
        dataCAT2.append(dataCAT1)
df1 = pd.concat(dataCAT2)
pythonrefinitiv-dataplatform-eikonscreener
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.

1 Answer

· Write an Answer
Upvotes
Accepted
5.7k 21 2 6

Hi @LRE42 ,


I tested your code and it works, even though it throws warning messages. Are you simply just trying to suppress these messages? If so, have you had a look on StackOverflow? I found the following which I think may be of use:

https://stackoverflow.com/questions/14463277/how-to-disable-python-warnings

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.

Thanks -- so I think this code is still working, based on what you're saying -- it's not stopping my Refinitiv query; it's just throwing an error on one iteration but is still giving me a result on the iterations that do work.

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.