代码
import numpy as np
import pandas as pd
from pandas import Series,DataFrame
data = Series(np.random.randn(10),
index=[
['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'd', 'd', ],
[1, 2, 3, 1, 2, 3, 4, 5, 6, 7]
])
print( data )
print('-------------------------')
print( data ['b'])
print('-------------------------')
print( data ['b':'c'])
代码
print( data )
print( data.unstack() ) #转化成DataFrame二维数组
print( data.unstack().stack() ) #又转化成一维数组