MulDataFrame.reset_index#
- MulDataFrame.reset_index(columns=None, drop=False, inplace=False, col_fill='')#
Reset the columns of the index dataframe as the columns of the MulDataFrame.
Parameters#
- columnscolumn name(s) of the index dataframe.
If this argument is None, reset the index of the index dataframe. If the name of this index is None, it will be named as “primary_index”. If “primary_index” exists in the primary columns, it will be named as “primary_index_1” and so on.
- dropbool, default False
Just reset the index, without inserting index dataframe’s column(s) as column(s) in the new MulDataFrame.
- inplacebool, default False
Modify the MulDataFrame in place (do not create a new object).
- col_fillobject, default ‘’
A scalar, a pandas Series or a pandas DataFrame to fill in the columns dataframe of the new MulDataFrame (inplace=False) or the modified MulDataFrame (inplace=True) for the inserted values. If the argument is a Series or a DataFrame, its index should align with the columns of the muldataframe’ columns dataframe in the same way as the align mode in the constructor.
Returns#
- MulDataFrame or None
The return value behaves similarly to DataFrame.reset_index.
Examples#
>>> import pandas as pd >>> import muldataframe as md >>> index = pd.DataFrame([[1,2],[3,6],[5,6]], index=['a','b','b'], columns=['x','y']) >>> columns = pd.DataFrame([[5,7],[3,6]], index=['c','d'], columns=['f','g']) >>> md = MulDataFrame([[1,2],[8,9],[9,10]],index=index,columns=columns) >>> md.reset_index() (3, 2) g 7 6 f 5 3 primary_index c d -------- ----------------------- x y primary_index c d 0 1 2 0 a 1 2 1 3 6 1 b 8 9 2 5 6 2 b 9 10
Add a col_fill:
>>> ss_fill = pd.Series([8,9],index=['g','f'],name='primary_index')) >>> md.reset_index(col_fill=ss_fill) (3, 2) g 8 7 6 f 9 5 3 primary_index c d -------- --------------------- x y primary_index c d 0 1 2 0 a 1 2 1 3 6 1 b 8 9 2 5 6 2 b 9 10
MulDataFrame