How do I turn my get_data() output into a dataframe?

How do I turn my get_data() output into a dataframe? I'd like the index to be the RIC and the column headings to be the fields.

I believe the output is currently a tuple.

#import packages
import eikon as ek # the Eikon Python wrapper package
import pandas as pd
import numpy as np
import datetime from datetime
import timedelta, date, datetime
from dateutil.relativedelta import relativedelta

#connects to Bill's Eikon terminal
ek.set_app_key('XXXX')

test_1 = ek.get_data('TSLA.O',
['TR.NumOfStrongBuy',
'TR.NumOfBuy',
'TR.NumOfHold',
'TR.NumOfSell',
'TR.NumOfStrongSell'])

print(test_1)
Thanks

Best Answer

  • Hello @bill39

    Normally, get_data(..) returns pandas.DataFrame and errors as explained in Eikon Data APIs for Python - Reference Guide.

    The example source code below shows how to get DataFrame and the index to be the RIC and the column headings to be the fields.

    #return dataframe and errors
    test_1,err= ek.get_data('TSLA.O', 
            ['TR.NumOfStrongBuy',
             'TR.NumOfBuy',
             'TR.NumOfHold',
             'TR.NumOfSell',
             'TR.NumOfStrongSell'])
    print(type(test_1))
    #set index to be RIC
    test_1.set_index('Instrument', inplace=True) 
    #show data
    test_1

    The example output:

    image