unstack stack

unstack stack

stack:将数据的列“旋转”为行
unstack:将数据的行“旋转”为列

import numpy as np
import pandas as pd
from pandas import Series,DataFrame
data=DataFrame(np.arange(6).reshape((2,3)),index=pd.Index(['street1','street2']),columns=pd.Index(['one','two','three']))
print(data)
print('-----------------------------------------\n')
data2=data.stack()
data3=data2.unstack()
print(data2)
print('-----------------------------------------\n')
print(data3)

unstack stack_第1张图片

你可能感兴趣的:(pandas)