从Quandl检索库存数据时,我哪里出错了?

时间:2019-04-12 04:33:15

标签: python api dataframe stock quandl

$reportData = $this->report->run(); // Depending on the filters of the report, it can get upto 20,000 rows.
$headers = Input::get('selectedcolumns');

$data = [];
foreach($report['data'] as $value) {
    $row = [];
    foreach($headers as $header) {
        $row[$header['label']] = $value[$header['name']];
    }
    $data[] = $row;
}

return Excel::create('Excel', function($excel) use($data) {
    $excel->sheet('Sheet1', function($sheet) use($data) {
        ->sheet->fromArray($data);
    });
})->store('xls', false, true);

我正在尝试从Quandl中检索一些简单的库存数据。我在下面的示例代码中输入了实际的API密钥而不是x,但是仍然出现错误。我错过了什么吗?

ValueError: The Quandl API key must be provided either through the api_key variable or through the environmental variable QUANDL_API_KEY.

2 个答案:

答案 0 :(得分:1)

来自quandl docs

  

身份验证Quandl Python模块是免费的,但您必须拥有一个   Quandl API密钥才能下载数据。要获得自己的API密钥,您可以   将需要创建一个免费的Quandl帐户并设置您的API密钥。

     

导入Quandl模块后,您可以使用   以下命令:quandl.ApiConfig.api_key = "YOURAPIKEY"

因此,您将需要安装pip和import quandl。然后,您可以如上所述设置api_key属性。

答案 1 :(得分:1)

如果您只想从Quandl中获取数据,也许您可​​以尝试另一种方法。

import pandas as pd
import Quandl

api_key = 'yoursuperamazingquandlAPIkey'
df = Quandl.get('heregoesthequandlcode', authtoken = api_key)

print(df.head())