how to retrieve the specific field from data?




eur=ek.get_data("EUR=FXAL",



{'CF_BID':{}},


{'CF_ASK':{}},


{'CF_LAST':{}},


{'CF_CLOSE':{}},




print(eur)

Result:

( Instrument CF_BID
CF_ASK CF_LAST CF_CLOSE0 EUR=FXAL
1.1704 1.17052 1.1704
1.17187, None)

For example,if i only want to retrieve 1.1704 from result ,how can i do?Thank you.

Best Answer

Answers

  • pf
    pf LSEG

    You should retrieve separately result and error from get_data :
    >>> eur, error = ek.get_data("EUR=FXAL", ["CF_BID", "CF_ASK", "CF_LAST", "CF_CLOSE"])

    >>> eur
    Instrument CF_BID CF_ASK CF_LAST CF_CLOSE

    0 EUR=FXAL 1.17042 1.17056 1.17042 1.17187

    Then, you can retrieve the CF_BID value :
    >>> eur.iloc[0][1] (or eur["CF_BID"][0] )

    1.17042

    For CF_CLOSE, just modify the index :

    >>> eur.iloc[0][4] (or eur["CF_CLOSE"][0] )

    1.17187

    edit: a like for Nick's answer that give a field name access !