Pull news headlines together with RIC or ISIN identifier

Dear support,

For pulling news headlines for a specific universe we currently make a list of RICs, and use a for loop to iterate over them and get headlines for all the RICs in the list.

The outputted data frame has more than one news headline for each company. We would like to add an adjacent column to the output with the pertinent identifier (RIC or ISIN). To be able to know what company the headlines pertain to. Could you help us figure out how to add that to the for loop using the ek.get_news_headlines function?


Thanks in advance


See our current code below:

df1 = pd.DataFrame()

RIC_List

for ric in RIC_List:

q='R:'+ ric + ' AND Topic:ESG AND Language:LEN'

#print(q)

df = ek.get_news_headlines(q,count=3, date_from='2020-09-15T09:00:00', date_to='2020-10-08T18:00:00')

df1 = df1.append(df)

Best Answer

  • H @Erik77 - so the best place to do this is right after you get the return from the API, see below:

    RIC_List = ['VOD.L','IBM.N']
    df1 = pd.DataFrame()
    RIC_List

    for ric in RIC_List:
        q='R:'+ ric + ' AND Topic:ESG AND Language:LEN'
        df = ek.get_news_headlines(q,count=3, date_from='2020-09-15T09:00:00', date_to='2020-10-08T18:00:00')
        df['RIC1'] = ric
        df1 = df1.append(df)

    image

    I hope this can help.