import pandas as pd bigmac = pd.read_csv('bigmac.csv',parse_dates=['Date']) bigmac.dtypes bigmac.info() bigmac.set_index(keys=['Date','Country']) bigmac.head(3) bigmac.set_index(keys=['Country','Date']) bigmac.head(3) bigmac.set_index(keys=['Date','Country'],inplace=True) bigmac.sort_index() bigmac.index bigmac.index[0][0] bigmac.values[1] bigmac.index.get_level_values(1).unique() bigmac.index.get_level_values('Date') bigmac.index.get_level_values('Date').unique() bigmac.index.set_names(['Day','Location'], inplace=True) bigmac.head(3) bigmac.sort_index(ascending=[True,False],inplace=True) bigmac.head(3) bigmac.loc[('2016-01-01','Brazil')] bigmac.loc[('2016-01-01'),['Price in US Dollars']] bigmac.ix[('2010-01-01','Brazil'),0]
Friday, April 20, 2018
Multiindex in Pandas
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment