python-3.xquandl

get only a value with Quandl in Python


I'm working with Quandl. I had search in the documentation but I cant find it

import quandl

quandl.ApiConfig.api_key = 'PNPLwChDhr6UMUVvfc5h'
gold = quandl.get('LBMA/GOLD', rows=1, column_index='2')

print(gold)

When I run it, the console shows:

  USD (PM)
Date                
2020-08-13   1944.25

But, I only need it 1944.25 to compare it then with an if statement. How can print only the specific value?


Solution

  • code:

    import quandl
    
    quandl.ApiConfig.api_key = 'your-api-key'
    gold = quandl.get('LBMA/GOLD', rows=1, column_index='2')
    
    print(gold.iloc[0].values[0])
    

    Output:

    1944.75