2017-05-04 2 views
2

이것은 간단해야하지만 몇 시간 동안 검색 한 후에도 내가 잘못하고있는 것에 대해 여전히 손실이 있습니다.팬더 행에 대한 다중 레벨 인덱스

MultiIndexing.from_ 및 다른 여러 가지 방법을 사용하여 다른 방법을 시도했지만이 권한을 얻을 수 없습니다.

내가 좋아하는 뭔가가 필요합니다
enter image description here

을하지만 그 대신 내가 얻을 : 내가 잘못 뭐하는 거지
enter image description here ?

import pandas as pd 

list_of_customers = ['Client1', 'Client2', 'Client3'] 
stat_index = ['max', 'current', 'min'] 
list_of_historic_timeframes = ['16:10', '16:20', '16:30'] 

timeblock = pd.DataFrame(index=([list_of_customers, stat_index]), columns=list_of_historic_timeframes) 
timeblock.fillna(0, inplace=True) 

print(timeblock) 

답변

3
list_of_customers = ['Client1', 'Client2', 'Client3'] 
stat_index = ['max', 'current', 'min'] 
list_of_historic_timeframes = ['16:10', '16:20', '16:30'] 


timeblock = pd.DataFrame(
    0, 
    pd.MultiIndex.from_product(
     [list_of_customers, stat_index], 
     names=['Customer', 'Stat'] 
    ), 
    list_of_historic_timeframes 
) 

print(timeblock) 

        16:10 16:20 16:30 
Customer Stat       
Client1 max   0  0  0 
     current  0  0  0 
     min   0  0  0 
Client2 max   0  0  0 
     current  0  0  0 
     min   0  0  0 
Client3 max   0  0  0 
     current  0  0  0 
     min   0  0  0 
+0

신난다! 고맙습니다. 여러 예제를 살펴본 후에도 MultiIndex를 잘못 사용하고 잘못된 from_을 사용하고있었습니다. – GeorgeLPerkins

+0

@GeorgeLPerkins 당신을 진심으로 환영합니다. – piRSquared

+0

이제 특정 값을 업데이트해야합니다. 다차원 Numpy 배열을 사용하는 방법을 알고 있지만 어떤 이유로이 값을 올바르게 처리하지 못합니다. 전체 행을 업데이트 할 수 있지만 열을 올바르게 지정할 수 없습니다. – GeorgeLPerkins

관련 문제