MulSeries#

class muldataframe.MulSeries(data, index: DataFrame = None, name: Series | str | None = None, index_init: Literal['overlap'] | Literal['override'] | Literal['align'] = None, index_copy=True, name_copy=True, data_copy=None)#

A multi-index series with the index being a pandas dataframe and the name a pandas series. It also has an underlying values series that is not directly accessible. Its values are the same as the values of the values series.

Parameters#

data: pandas.Series, array-like, Iterable, dict, or scalar value

either a pandas Series or the same kind of data argument as required in the pandas Series constructor. The values series is constructed from the data argument.

index: pandas.DataFrame

If index is None, construct an empty index dataframe using the index of the values series as its index.

name: pandas.Series, str

If name is of str type, construct an empty name series using name as its name. If name is None, construct an empty name series using the name of the values series as its name.

index_init: Literal[‘overlap’] | Literal[‘override’] | Literal[‘align’]

The option determins how to align the index of the index dataframe to the index of the values series.

  • ‘overlap’ : The overlap of the index of the index dataframe and the index of the values series is used to index the values series and the index dataframe. This mode requires both indexes being unique.

  • ‘override’ : the index of the index dataframe overrides the index of the values series. This mode requires both indexes’ lengths to be the same.

  • ‘align’ : This mode is only effective if the data argumnet implies an index and the index argument is not None. In this mode, the index of the index dataframe is used to index the values series constructed from the data argument. The resulting series is used as the final values series. It requires the index of the values series being uinque and have all the labels in the index dataframe’s index.

  • None : the default behavior depends on the type of the data argument. If data implies a row index such as if it is a pandas.Series object or a dict, the mode will be 'overlap`. Otherwise, it will be 'override'.

Of note, when data implies a row index and this index is the same as the index of the index dataframe, the 'override' mode will be used even if other modes are specified. In all three modes, the name of the initialized primary index will be the same as the name of the index of the index dataframe.

index_copy: bool

whether to create a copy of the index argument.

name_copy: bool

whether to create a copy of the name argument.

data_copybool, default None

Wether to copy data. It behaves the same as the copy argument in pandas.Series.__init__

Examples:#

Construct a mulseries. Notice that the index of the dataframe and the index of the values series are the same and the name of the name series and the name of the values series are the same.

>>> import pandas as pd
>>> import muldataframe as md
>>> index = pd.DataFrame([[1,2],[3,5],[3,6]],
                        index=['a','b','b'],
                        columns=['x','y'])
>>> name = pd.Series(['g','h'],index=['e','f'], name='cc')
>>> ms = md.MulSeries([1,2,3],index=index,name=name)
>>> ms
(3,)     f   h
         e   g
            cc
-------  ------
   x  y     cc
a  1  2  a   1
b  3  5  b   2
b  3  6  b   3