2014-10-02 2 views
0

instructions provided in the online documentation을 사용하여 pandas 패널 객체를 복사하려고하면 예상 한 바쁨을 얻지 못합니다. (내 유일한 책을팬더 패널의 딥 복사?

import pandas as pd 

# make first panel with some bogus numbers 
dates = pd.date_range('20130101',periods=6) 
df1 = pd.DataFrame(np.random.randn(6,4),index=dates,columns=list('ABCD')) 
df2 = pd.DataFrame(np.random.randn(6,4),index=dates,columns=list('EFGH')) 
pnl = {} 
pnl['alpha'] = df1 
pnl['beta'] = df2 

# copy pnl into pnl2 
# according to online docs the default is 'deep=True' 
# but it chokes when I try to specify deep=True 
pnl2 = pnl.copy() 


# now delete column C from pnl2['alpha'] 
del pnl2['alpha']['C'] 



#Now when I try to find column C in the original panel (pnl) it's gone! 

나는이에 매끄러운 해결책이 있어야 그림,하지만 난 온라인 문서에서 찾을 수없는,도 웨스 맥키 니의 책 :

아마이 문제를 설명합니다 팬더에 ...).

모든 도움말/많은 의견 부탁드립니다.

답변

1

당신은 패널을 만들지 않았으며 단지 DataFrames의 단서를 작성했습니다. 이 줄을 추가하여 Panel 객체로 변환하면 예상대로 작동합니다.

pnl = pd.Panel(pnl) 
+1

DOH! 고맙습니다. 프로그램을 작성하는 것은 겸손의 재배에 큰 도움이되고 있습니다. –