如何将比特币数据集和 google 组合成一个数据框,如下所示?
How to combine a bitcoin dataset and google into one dataframe as following?
你能告诉我如何更正以下内容吗?当我运行它时,出现错误。
ValueError:索引包含重复条目,无法重塑
import datetime
import pandas_datareader.data as web
# set start and end dates
start = datetime.datetime(2018, 2, 15)
end = datetime.datetime(2020, 2, 14)
# extract the closing price data
combined_df = web.DataReader(["BTC-USD","ETH-USD","GOOG"],
"yahoo", start = start, end = end)
import datetime
import pandas as pd
import numpy as np
import yfinance as yf
# pip install yfinance
# updated version of yahoo_datareader
start = datetime.datetime(2018, 2, 15)
end = datetime.datetime(2020, 2, 14)
symbols = ['BTC-USD', 'ETH-USD', 'GOOG']
df = pd.DataFrame()
for i in symbols:
data = yf.download(i, start, end)
df[i] = data['Adj Close']
df = df.fillna(method='ffill')
ind = list(df.index)
df.index = list(range(len(df.index)))
for i in df.index:
if df['GOOG'].iloc[i] == 0:
df['GOOG'].iloc[i] = df['GOOG'].iloc[i-1]
changes = []
for i in df.index:
if i == 0:
changes.append(0.)
else:
current = df['GOOG'].iloc[i]
previous = df['GOOG'].iloc[i-1]
perc_change = np.round(((current - previous) / previous)*100),2)
changes.append(perc_change)
df['% Change'] = changes
df.index = ind
你能告诉我如何更正以下内容吗?当我运行它时,出现错误。
ValueError:索引包含重复条目,无法重塑
import datetime
import pandas_datareader.data as web
# set start and end dates
start = datetime.datetime(2018, 2, 15)
end = datetime.datetime(2020, 2, 14)
# extract the closing price data
combined_df = web.DataReader(["BTC-USD","ETH-USD","GOOG"],
"yahoo", start = start, end = end)
import datetime
import pandas as pd
import numpy as np
import yfinance as yf
# pip install yfinance
# updated version of yahoo_datareader
start = datetime.datetime(2018, 2, 15)
end = datetime.datetime(2020, 2, 14)
symbols = ['BTC-USD', 'ETH-USD', 'GOOG']
df = pd.DataFrame()
for i in symbols:
data = yf.download(i, start, end)
df[i] = data['Adj Close']
df = df.fillna(method='ffill')
ind = list(df.index)
df.index = list(range(len(df.index)))
for i in df.index:
if df['GOOG'].iloc[i] == 0:
df['GOOG'].iloc[i] = df['GOOG'].iloc[i-1]
changes = []
for i in df.index:
if i == 0:
changes.append(0.)
else:
current = df['GOOG'].iloc[i]
previous = df['GOOG'].iloc[i-1]
perc_change = np.round(((current - previous) / previous)*100),2)
changes.append(perc_change)
df['% Change'] = changes
df.index = ind