2016-11-05 77 views
0

我在字典中有一系列數據幀。更改熊貓數據幀索引的值

type(mydict[0]) 
pandas.core.frame.DataFrame 

print(dict[0]) 

      0   1   2 
0 0.278735 0.609862 0.085823 
1 0.836997 0.739635 0.866059 
2 0.691271 0.377185 0.225146 

print(dict[1]) 

      0   1   2 
3 0.435280 0.700900 0.700946 
4 0.796487 0.018688 0.700566 
5 0.900749 0.764869 0.253200 

我如何的dict[1]指數的值更改爲,使得它看起來像這樣

print(dict[0]) 

      0   1   2 
0 0.278735 0.609862 0.085823 
1 0.836997 0.739635 0.866059 
2 0.691271 0.377185 0.225146 

print(dict[1]) 

      0   1   2 
0 0.435280 0.700900 0.700946 
1 0.796487 0.018688 0.700566 
2 0.900749 0.764869 0.253200 

回答

2

嘗試:

mydict[1].reset_index(drop=True, inplace=True) 
+0

感謝這個工作對我的簡單的例子。不幸的是,當dict [1]是一個multiIndex數據框,其中有兩個級別,我試圖重置的索引位於level = 1時,它似乎不工作。我在df:df [i] = self.data [i] .reset_index(level = 1,drop = True,inplace = True)時嘗試了''但是'print(mydict [1])'產生'None'好回答。在我的部分簡單的例子。 – agf1997

+0

inplace = True將使該函數返回None。不要分配功能結果 – Boud

+0

太棒了!謝謝。非常有意義。 – agf1997