遵循教程时使用 Alpha Vantage 时出错,- Pylint 错误

Error using Alpha Vantage while following tutorial, - Pylint error

我正在学习 alpha vantage 包,我一直在学习 Derrick Sherrill 的教程 https://www.youtube.com/watch?v=JJO9fKj3_u4,但我 运行 遇到了一些问题。

这是我的代码:

import pandas as pd
from alpha_vantage.techindicators import TechIndicators
from alpha_vantage.timeseries import TimeSeries
import matplotlib.pyplot as plt

api_key = 'XXXX'

ts = TimeSeries(key=api_key, output_format='pandas')
data_ts, meta_data_ts = ts.get_intraday(
symbol='MSFT', interval='1min', outputsize='full')

period = 60

ti = TechIndicators(key=api_key, output_format='pandas')
data_ti, meta_data_ti = ti.get_sma(
symbol='MSFT', interval='1min', time_period=period, series_type='close')

df1 = data_ti
df2 = data_ts['4. close'].iloc[period-1::]

df2.index = df1.index

total_df = pd.concat([df1, df2], axis=1)
print(total_df)

在定义变量 df2 时,我得到一条红色下划线并告诉我:

Sequence index is not an int, slice, or instance with __index__pylint(invalid-sequence-index)

虽然我不确定这是问题所在。

我很确定我应该得到一组数据,但目前情况并非如此。

这是尝试 运行 脚本后的完整终端消息:

  File "/Users/ludvighenriksen/Desktop/Code/api.py", line 15, in <module>
    data_ti, meta_data_ti = ti.get_sma(symbol='MSFT', interval='1',
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/alpha_vantage/alphavantage.py", line 218, in _format_wrapper
    call_response, data_key, meta_data_key = func(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/alpha_vantage/alphavantage.py", line 160, in _call_wrapper
    return self._handle_api_call(url), data_key, meta_data_key
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/alpha_vantage/alphavantage.py", line 337, in _handle_api_call
    raise ValueError(json_response["Error Message"])
ValueError: Invalid API call. Please retry or visit the documentation (https://www.alphavantage.co/documentation/) for SMA.

希望您能提供帮助,在此先感谢!

这里有些误会。

您在 df2 下看到的红线曲线是来自 pylint 文档的 pylint error. Pylint is a form of linting tool, which can often find parts of your code that will break, but it also find stylistic errors. A stylistic error is an error of how you write your code, it may not actually break the code. The error you got can be found here

您可以通过几种方式禁用此 "code cleanness checker"。查看 here or here 了解更多信息。 Mac:Command+Shift+P > 键入 "python: enable linting" > 设置 "off" Windows: CTRL+SHIFT+P > Select linter > 禁用 Linter。

你得到的原始错误似乎是之前的一些用户错误,也许你有错误的符号,但你的输出截图似乎没有重现错误。