How to have common company name and ticker symbol for all rows

Hi i am using the following code to retrieve data, however i am unable to pull the data of Company Common Name and Ticker Symbol for every single row it only appears on the first row. i need each row to be filled up with the company common name and ticker symbol.


I have tried fill na forward fill method, but it does not work.


df1, err = ek.get_data(

instruments = ['AAPL.O',

'GOOGL.O',

],

fields = [

'TR.CommonName',

'TR.TickerSymbol',

'TR.PriceClose',


],

parameters = {'SDate': '2023-01-01', 'EDate': '2023-04-06'}

)

Best Answer

  • aramyan.h
    Answer ✓

    Hi @ken03 ,


    As specified in this thread, since some fields (in this case Company name and Symbol) doesn't support time series you get the value for the first row and the rest is returned as empty strings. One approach I can suggest is replacing the empty fields by np.nan and filling forward nan fields using the code below:

    import numpy as np
    df1['Company Common Name'].replace('', np.nan, inplace = True)
    df1['Company Common Name'].fillna(method = 'ffill', inplace = True)
    df1['Ticker Symbol'].replace('', np.nan, inplace = True)
    df1['Ticker Symbol'].fillna(method = 'ffill', inplace = True)
    df1


    screenshot-2023-04-06-at-102744.png


    Hope this helps.


    Best regards,

    Haykaz