How to pull all public company actual revenue by country and industry in Codebook

Hello,

I have tried this script in Codebook but get an error. Can you help me adjust the code to work?

end goal: dataset for all public companies (~68k companies) with columns Country | Industry | Actual Revenue Q1'25

We would love to also have more quarters of historical data as well.

Here is the current code


import lseg.data as ld
from lseg.data.discovery import Screener
from lseg.data.discovery import Peers
import datetime
from IPython.display import display, clear_output

Open session

ld.open_session()

Define the screener query

query = Screener(
'U(IN(Equity(active,public,primary))/UNV:Public/), TR.CompanyMarketCap(Scale=3)>=1, CURN=USD'
)

Define the fields to retrieve

fields = [
'TR.CommonName',
'TR.HeadquartersCountry',
'TR.RevenueActValue(SDate=0,EDate=-3,Period=FQ0,Frq=FQ)'
]

Define parameters

params = {'curn': 'USD'}

Get data

df = ld.get_data(query, fields, params)

Remove duplicates based on company name

df = df.drop_duplicates(subset='TR.CommonName')

Display the result

display(df)

Here is the current error

---------------------------------------------------------------------------LDError                                   Traceback (most recent call last)/tmp/ipykernel_140/1493526482.py in <module>     24      25 # Get data---> 26 df = ld.get_data(query, fields, params)     27      28 # Remove duplicates based on company name/opt/conda/lib/python3.8/site-packages/lseg/data/_access_layer/get_data_func.py in get_data(universe, fields, parameters, header_type)     85      86     if can_use_eikon_approach:---> 87         return _get_data_eikon_approach(universe, fields, parameters, header_type, session)     88      89     return _get_data(universe, fields, parameters, header_type, session)/opt/conda/lib/python3.8/site-packages/lseg/data/_access_layer/get_data_func.py in _get_data_eikon_approach(universe, fields, parameters, header_type, session)    136         exceptions.append(exception_msg)    137 --> 138     raise_if_all(exceptions)    139     140     adc_data = ADCContainerEikonApproach(adc_raw, fields)/opt/conda/lib/python3.8/site-packages/lseg/data/_access_layer/get_data_func.py in raise_if_all(exceptions)     92 def raise_if_all(exceptions: List[str]):     93     if exceptions and all(exceptions):---> 94         raise LDError(message="\n\n".join(exceptions))     95      96 

Answers

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @markrogers116

    Thank you for reaching out to us.

    You can try this one.

    screener_expression = 'SCREEN(U(IN(Equity(active,public,primary))), TR.CompanyMarketCap(Scale=3)>=1, CURN=USD)'
    
    fields = [
    'TR.CommonName',
    'TR.HeadquartersCountry',
    'TR.RevenueActValue(SDate=0,EDate=-3,Period=FQ0,Frq=FQ)'
    ]
    
    
    params = {'curn': 'USD'}
    
    
    df = ld.get_data(screener_expression, fields, params)
    
    df
    

    However, the response contains 110,797 entries.

    image.png

    When requesting a large volume of data, the request may time out. To avoid this, consider adding additional filters to the screener expression to reduce the size of the response.