2017-05-04 7 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

関連する問題