min(), max(), median(), mean(), and mode()

These functions accept a similar set of parameters and compute the aggregates (min, max, median, or mode) for each column or row based on the axis parameter setting:

sales_df.min()

The following is the output:

The min() result

The max method can be applied as shown here:

sales_df.max(axis = 1)

The following is the output:

The max() result

The skipna parameter helps us handle NAs. Consider the following DataFrame:

sales_df_na

The following is the output:

DataFrame with NAs

By default, the NAs are skipped during evaluation, as the skipna parameter is set to True:

sales_df_na.median()

The following is the output:

The median() function

By default, NAs are ignored in mean calculations. If skipna is set to False, the calculation also result to NA if there is a missing value:

sales_df_na.median(skipna = False)

The following is the output:

The median() function with skipna

Consider the following multi indexed DataFrame. Let's compute the mean for it:

multileveldf

The following is the output:

Multi indexed DataFrame

The mean of this multi-index dataset can be obtained as shown here:

multileveldf.mean()

The following is the output:

The mean of the multi indexed DataFrame

The level parameter computes the aggregate across any level of index in a multi-indexed DataFrame:

multileveldf.mean(level = 0)

The following is the output:

mean() for a specific index level
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.125.227