Hierarchical Indexing In Pandas
import numpy as np
import pandas as pd 1. CREATING MULTI-INDEXED SERIES
# defining multi-index in form of tuples
index = [('City A', 2018),('City A', 2019),
('City B', 2018), ('City B', 2019),
('City C', 2018), ('City C', 2019)]
index[('City A', 2018),
('City A', 2019),
('City B', 2018),
('City B', 2019),
('City C', 2018),
('City C', 2019)]# creating multi-index in Pandas from Tuples (we created above)
index_pd = pd.MultiIndex.from_tuples(index)
index_pd1.1. Stack and Unstack
a. unstack Method
b. stack
1.2. Handling three or more Dimensions
1.3. Applying UFunc
2. VARIOUS METHODS OF MULTI-INDEX CREATION
2.1. Explicit Multi-index constructors
a. from_arrays
b. from_tuples
c. from_product
2.2. Multi-Index level names
a. Directly as argument in Explicit Multi-Index constructor
b. By setting index.name for Series or DataFrame
2.3. Multi-levels for Columns
3. INDEXING AND SLICING A MULTI-INDEX
3.1. Multi-Index Series
3.2. Multi-Index DataFrame
4. REARRANGING MULTI-INDICES
4.1. Sorted and Unsorted indices
4.2. Stacking and Unstacking indices
a. Unstack
b. Stack
4.3. Index Resetting and Setting
a. Index Reset
b. Set Index
5. DATA AGGREGATIONS ON MULTI-INDICES
a. Along rows
b. Along column and rows
Last updated