Python;Pandas;DataFrame;MultiIndex;有多重索引的DataFrame数据格式的引用方法
import pandas as pd
import numpy as np
se1=pd.Series(np.random.randn(4),index=[list("aabb"),[1,2,1,2]])
print(se1)
a 1 -0.172952
2 1.032693
b 1 0.760707
2 -0.281595
dtype: float64
有多重索引的Series的引用方法
print(se1['a'])
print('\r\n')
print(se1['a':'b'])
1 -0.172952
2 1.032693
dtype: float64
a 1 -0.172952
2 1.032693
b 1 0.760707
2 -0.281595
dtype: float64
print(se1[:,1])
print('\r\n')
print(se1['a',1])
a -0.172952
b 0.760707
dtype: float64
-0.1729515873577343
DataFrame的行和列都可以是多重索引
df1=pd.DataFrame(np.arange(18).reshape(6,3),index=[list("AAABBB"),[1,2,3,1,2,3]],columns=[list("XXY"