Filter for organizations with Empty GicsCode category via Python API

Using the Python Refinitiv.data API I want to filter for organizations without a GICS code. How can I setup the filter query to exactly filter for "" (empty string?)

This is the code I am using:

import refinitiv.data as rd
rd.open_session()

response = search.Definition(
view = search.Views.ORGANISATIONS,
filter = f"GicsCode xeq ''",
select = 'OAPermID,CommonName,GicsCode',
top=10000 # maximum number of rows
).get_data()

The result is an Empty List.

The code works, because when filtering for a GicsCode such as 20106020 I retrieve 1573 organizations.

However, not all organizations have a GicsCode. For example "Fox E-Mobility AG", organization OAPermID "5071502736" does not have a GicsCode, value is empty. How can I setup a filter to select organizations that do not have a Gics Code?

I would like to have an answer like filter req '' or isEmpty? Thanks

Best Answer

  • Jirapongse
    Answer ✓

    @r.fernandez

    Thank you for reaching out to us.

    Please try this one:

    response = search.Definition(
                    view = search.Views.ORGANISATIONS,
                    filter = f"GicsCode eq null",
                    select = 'OAPermID,CommonName,GicsCode',
                    top=100 # maximum number of rows
                ).get_data()
    response.data.df

    1714368108297.png


Answers

  • Hi @Jirapongse
    Thanks for responding so quickly. Do you know if there is any formal documentation on the filter query language used? I'm also searching for ways to escape the quote sign, I'm getting the error for searching

    key = "US 'Other OTC' and Grey Market"

    Invalid filter: unexpected <s> immediately after string <'US '> (hint: escape literal <'> as <''>)
  • @r.fernandez

    The document is on the API docs.

    Please share the full code that you are using.