国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

對Pandas MultiIndex(多重索引)詳解

2020-02-15 23:43:14
字體:
來源:轉載
供稿:網友

創建多重索引

In [16]: df = pd.DataFrame(np.random.randn(3, 8), index=['A', 'B', 'C'], columns=index)In [17]: dfOut[17]: first  bar     baz     foo     qux /second  one  two  one  two  one  two  one A  0.895717 0.805244 -1.206412 2.565646 1.431256 1.340309 -1.170299 B  0.410835 0.813850 0.132003 -0.827317 -0.076467 -1.187678 1.130127 C  -1.413681 1.607920 1.024180 0.569605 0.875906 -2.211372 0.974466 first    second  two A  -0.226169 B  -1.436737 C  -2.006747 

獲得索引信息

get_level_values

In [23]: index.get_level_values(0)Out[23]: Index(['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'], dtype='object', name='first')In [24]: index.get_level_values('second')Out[24]: Index(['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two'], dtype='object', name='second')

基本索引

In [25]: df['bar']Out[25]: second  one  twoA  0.895717 0.805244B  0.410835 0.813850C  -1.413681 1.607920In [26]: df['bar', 'one']Out[26]: A 0.895717B 0.410835C -1.413681Name: (bar, one), dtype: float64In [27]: df['bar']['one']Out[27]: A 0.895717B 0.410835C -1.413681Name: one, dtype: float64

使用reindex對齊數據

數據準備

In [11]: s = pd.Series(np.random.randn(8), index=arrays)In [12]: sOut[12]: bar one -0.861849  two -2.104569baz one -0.494929  two 1.071804foo one 0.721555  two -0.706771qux one -1.039575  two 0.271860dtype: float64

s序列加(0~-2)索引的值,因為s[:-2]沒有最后兩個的索引,所以為NaN.s[::2]意思是步長為1.

In [34]: s + s[:-2]Out[34]: bar one -1.723698  two -4.209138baz one -0.989859  two 2.143608foo one 1.443110  two -1.413542qux one   NaN  two   NaNdtype: float64In [35]: s + s[::2]Out[35]: bar one -1.723698  two   NaNbaz one -0.989859  two   NaNfoo one 1.443110  two   NaNqux one -2.079150  two   NaNdtype: float64

以上這篇對Pandas MultiIndex(多重索引)詳解就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阜宁县| 通许县| 利川市| 雷山县| 灵川县| 塘沽区| 库尔勒市| 库伦旗| 吐鲁番市| 沂水县| 固始县| 滦南县| 鄂尔多斯市| 吴江市| 柞水县| 荃湾区| 宜君县| 资阳市| 巴东县| 黄龙县| 阿荣旗| 沂水县| 江永县| 凉山| 周口市| 从化市| 喀喇| 温州市| 利辛县| 金溪县| 黎城县| 徐汇区| 沧州市| 鄂尔多斯市| 柳林县| 靖江市| 岢岚县| 彭水| 鄂温| 泽州县| 海晏县|