따라서 다른 크기의 데이터 프레임을 넣으려고하면 항상 오류가 발생합니다.
import pandas as pd
from pandas import Series,DataFrame
import numpy as np
# For reading stock data from yahoo
import pandas_datareader as web
# For time stamps
from datetime import datetime
closing_df = web.DataReader(['AAPL','GOOG','MSFT','AMZN'],'yahoo',start,end)['Adj Close']
#when I do this, it is fine since the size are the same whereas
closing_df = web.DataReader(['AAPL','GOOG','MSFT','AMZN','BTC-USD'],'yahoo',start,end)['Adj Close']
#I always get this error
#ValueError: Index contains duplicate entries, cannot reshape
나는 두 개의 데이터 프레임, 하나는 기술 회사와 하나는 BTC-USD를 위해 노력했지만 join, concat 또는 merge를 사용하면 작동하지 않는 것 같습니다. 두 데이터 세트에 대한 모든 합동 날짜를 가져 와서 합치고 싶습니다. 두 데이터 프레임에 모두 2010-11-30이 있으면 데이터 프레임에 있지만 하나의 데이터 프레임에만 해당 날짜가 포함되어 있으면 무시하거나 공동 데이터 프레임에 넣지 않습니다. 많은 감사합니다
한 가지 해결 방법은 다음과 같습니다.
tech = web.DataReader(['AAPL','GOOG','MSFT','AMZN'],'yahoo', start, end)['Adj Close']
btc = web.DataReader('BTC-USD','yahoo', start, end)['Adj Close']
result_df = pd.merge(tech, btc, left_index=True, right_index=True).rename(columns={'Adj Close': 'BTC'})
그러나 단일 데이터 프레임을 확인하면 기술에는 재무 일만있는 반면 BTC에는 주말과 공휴일이 있으므로 전반적으로 다른 날짜를 검색하는 것처럼 보입니다. 위의 조인으로 BTC 데이터를 잃게됩니다. 외부 조인을 한 다음 값을 채우는 것이 더 나을 수 있습니다.
result_df = pd.merge(tech, btc, left_index=True, right_index=True,
how='outer').rename(columns={'Adj Close': 'BTC'})
result_df.fillna(method='ffill', inplace=True)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다