首页 » Python » 秦路天善智能python学习笔记-pandas的多重索引

秦路天善智能python学习笔记-pandas的多重索引

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import pandas as pd
position = pd.read_csv("DataAnalyst.csv",encoding="gbk",engine="python",sep=",")

position2 = position.groupby(by = ['city','education'])
print(position2.mean())

position3 = position.groupby(by = ['city','education']).mean().loc['上海']
print(position3)

position4 = position.groupby(by = ['city','education']).mean().loc['上海','博士']
print(position4)

position5 = position.sort_values(by=['city','education']).set_index(['city','education'])
print(position5)

position6 = position.groupby(by = ['city','education']).mean().reset_index()['city']
print(position6)

原文链接:秦路天善智能python学习笔记-pandas的多重索引,转载请注明来源!

0