1

I want to import two time series from Quandl and want to find the correlation between them. I found out about the pandas and tried with the corr function, however I always get the error ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). I really don't know what is wrong with this code, I printed the arrays and they look fine.

Here is my code:

import pandas as pd
import quandl

quandl.ApiConfig.api_key = "XXX"

series1 = quandl.get("BUNDESBANK/BBK01_WT5511", start_date="2017-01-01")
series2 = quandl.get("FRED/DCOILBRENTEU", start_date="2017-01-01")

print(series1.corr(series2))
Nurqm
  • 4,715
  • 2
  • 11
  • 35
bruketa22
  • 11
  • 1

1 Answers1

0

I was getting the same error. It turns out the problem was in how I was passing the API Key. Specifically, to avoid having exposed, plaintext API keys in my code I used

api_key = pd.read_csv('API Key File', header=None)

to read in my API Key, and then passed that to Quandl:

Quandl.ApiConfig.api_key = api_key

Then I got the same error as you: the truth value of a DataFrame is ambiguous.

As I dug in, I realized the pd.read_csv was the issue: type(api_key) gives an object, not a string. Thus I switched to the following to set the API Key:

with open('API Key File') as f:
    api_key = f.readline()

Then type(api_key) returns a string, and the exact same code you have above then works without the error. Hopefully this helps!

BLimitless
  • 2,060
  • 5
  • 17
  • 32