在https://yahooquery.dpguthrie.com/guide/ticker/historical/中显示图表的命令是什么
小时
我试过这个密码
import pandas as pd
import matplotlib.pyplot as plt
from yahooquery import Ticker
tickers = Ticker('aapl nflx', asynchronous=True)
df = tickers.history()
df["adjclose"].plot()
plt.xticks(rotation=90)
plt.show()
但它只是在图表中显示一个系列,如下所示:
小时
如何将aapl和nflx创建为一个图表上的两个系列?
2条答案
按热度按时间fjaof16o1#
symbol
和date
是 Dataframe 的索引。通过绘制整个 Dataframe ,可以按顺序绘制两个系列。这里有一种绘制每个股票行情的方法:
这使用
query
提取每个符号。mqxuamgl2#
首先,使用
df.pivot
将df
转换为更容易理解的形状,以便绘制方法:接下来,看看
sns.lineplot
:结果:
小时
顺便说一句,如果你想比较这两种股票,绘制百分比可能更有意义。例如。:
结果:
小时