1# assignment copy
2df = df.set_index('month')
3
4# or inplace
5df.set_index('month', inplace=True)
6
7# year sale month month year sale
8# 0 2012 55 1 1 2012 55
9# 1 2014 40 4 => 4 2014 40
10# 2 2013 84 7 7 2013 84
11# 3 2014 31 10 10 2014 31
1>>> df.set_index('month')
2 year sale
3month
41 2012 55
54 2014 40
67 2013 84
710 2014 31
8
1import numpy as np
2import pandas as pd
3df = pd.DataFrame({'month': [2, 5, 8, 10],
4 'year': [2017, 2019, 2018, 2019],
5 'sale': [60, 45, 90, 36]})
6df.set_index('month')
1>>> college_idx = college.set_index('instnm')>>> sats = college_idx[['satmtmid', 'satvrmid']].dropna()>>> sats.head()