Add index column wich is under a hierarchical index PANDAS/python

I want set the col1 as Index. The dataframe is the result of a concatenation and I using keys for created hierarchical index import pandas as pd d = {‘col1’: [0, 1, 2, 3], ‘col2’: pd.Series([2, 3], index=[2, 3])} df = pd.DataFrame(data=d, index=[0, 1, 2, 3]) d2 = {‘col1’: [0, 1, 4, 3], ‘col2’: pd.Series([4,… Read More Add index column wich is under a hierarchical index PANDAS/python

How to create hiearchical multi-index dataframe from multiple dataframes?

I have multiple dataframes with identical shape, say: d1 = {‘time’: [1,2,3,4], ‘A’: [55.5,55.5,55.5,55.5], ‘B’:[55.5,55.5,55.5,55.5]} d2 = {‘time’: [1,2,3,4], ‘A’: [7,6,5,4], ‘B’:[9,8,7,6]} d3 = {‘time’: [1,2,3,4], ‘A’: [1,2,3,4], ‘B’:[2,3,4,5]} df1 = pd.DataFrame(data = d1) df2 = pd.DataFrame(data = d2) df3 = pd.DataFrame(data = d3) They will always have the same column names and the entries… Read More How to create hiearchical multi-index dataframe from multiple dataframes?

How to create a multiIndex (hierarchical index) dataframe object from another df's column's unique values?

I’m trying to create a pandas multiIndexed dataframe that is a summary of the unique values in each column. Is there an easier way to have this information summarized besides creating this dataframe? Either way, it would be nice to know how to complete this code challenge. Thanks for your help! Here is the toy… Read More How to create a multiIndex (hierarchical index) dataframe object from another df's column's unique values?