I want to pull the data for the companies of specific exchange of a country. But I couldn't put the python code of the "Country of Headquarters" (Data Item Name), "TR.HeadquartersCountry" (Data Item Code) into my work.
result, err= ek.get_data('0#.FTSE', fields=esg)
How can I change the .FTSE with "TR.HeadquartersCountry". I don't want to see the companies in FTSE but I prefer to see "the companies that Country of Headquarters is UK".
You could screen for companies in the FTSE 100 that are headquartered in the UK:
screen = 'SCREEN(U(IN(indices(4932935/*FTSE 100*/))),IN(TR.HQCountryCode,"GB"))'
fields = ["TR.CommonName","TR.TRESGResourceUseScore(Period=FY0)","TR.TRESGEmissionsScore(Period=FY0)"]
df, e = ek.get_data(screen,fields)
Using screener expression, with get_data call, should yield the required result. I think you will find the article Find Your Right Companies with SCREENER | Eikon Data APIs(Python) very informative on how to define and use the screeners?