我有一个有关web.datareader的错误。出于某种原因,我不知道是什么引起的。什么好主意吗?
!pip install mplfinance
!pip install seaborn
!pip install matplotlib
import numpy as np
import pandas as pd
import mplfinance as mpf
import datetime as dt
import matplotlib.pyplot as plt
import seaborn as sns
currency = "USD"
metric = "Close"
start = dt.datetime(2018,1,1)
end = dt.datetime.now()
crypto = ['BTC', 'ETH', 'LTC', 'XRP', 'DASH', 'SC']
colnames = []
first = True
for ticker in crypto:
data = web.DataReader(f"{ticker}-{currency}", "yahoo", start, end)
if first:
combined = data[[metric]].copy()
colnames.append(ticker)
combined.columns = colnames
first = False
else:
combined = combined.join(data[metric])
colnames.append(ticker)
combined.columns = colnames
plt.yscale('log') # first show linear
for ticker in crypto:
plt.plot(combined[ticker], label=ticker)
plt.legend(loc="upper right")
plt.show()
# # Correlation Heat Map
print(combined)
combined = combined.pct_change().corr(method='pearson')
sns.heatmap(combined, annot=True, cmap="coolwarm")
plt.show()
您少了两行:
!pip install pandas-datareader
import pandas_datareader as web