透视表

import pandas as pd

# 构造数据
df = pd.DataFrame({'A': np.random.randint(3, size=(5, )), 'B': ['a', 'b', 'a', 'c', 'b'], 'C': np.random.randint(4, size=(5, ))})

# 透视表
df1 = df.pivot(index='A', columns='B', values='C')

# 重置索引
df1.reset_index(inplace=True)

df1.columns.name=None
1
2
3
4
5
6
7
8
9
10
11
12
df

df1

---------------------

posted @ 2019-08-15 12:47  水至清明  阅读(127)  评论(0编辑  收藏  举报