【发布时间】:2019-08-31 09:00:08
【问题描述】:
我正在尝试制作一个分析股票的程序,现在我编写了一个简单的 Python 脚本来绘制移动平均线。从本机路径中提取 CSV 文件可以正常工作,但是当我从 Web 获取它时,它不起作用。一直显示错误:“列表”对象没有属性“日期”
它在 .CSV 上运行良好,但网络上的东西搞砸了。 如果我运行 print(df),它会非常奇怪地显示表格。
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
df = pd.read_html("https://finance.yahoo.com/quote/AAPL/history?period1=1428469200&period2=1554699600&interval=1d&filter=history&frequency=1d")
x = df.Date
y = df.Close
a = df['Close'].rolling(50, min_periods=50).mean()
b = df['Close'].rolling(200, min_periods=200).mean()
plt.plot(x, y)
plt.plot(a)
plt.plot(b)
plt.savefig("AAPL Stuff")
我在 Jupyter Notebook 中运行。
我希望输出 [1] 是图表的图像,但我得到了错误:
AttributeError Traceback (most recent call last)
<ipython-input-18-d97fbde31cef> in <module>
4
5 df = pd.read_html("https://finance.yahoo.com/quote/AAPL/history?period1=1428469200&period2=1554699600&interval=1d&filter=history&frequency=1d")
----> 6 x = df.Date
7 y = df.Close
8
AttributeError: 'list' object has no attribute 'Date'
【问题讨论】:
标签: python pandas matplotlib plotly