# Pandas DataFrame median() Method

Rate this post

## Preparation

Before any data manipulation can occur, two (2) new libraries will require installation.

• The NumPy library supports multi-dimensional arrays and matrices in addition to a collection of mathematical functions.

To install these libraries, navigate to an IDE terminal. At the command prompt (`\$`), execute the code below. For the terminal used in this example, the command prompt is a dollar sign (`\$`). Your terminal prompt may be different.

`\$ pip install pandas`

Hit the `<Enter>` key on the keyboard to start the installation process.

`\$ pip install numpy`

Hit the `<Enter>` key on the keyboard to start the installation process.

If the installations were successful, a message displays in the terminal indicating the same.

Feel free to view the PyCharm installation guide for the required libraries.

Add the following code to the top of each code snippet. This snippet will allow the code in this article to run error-free.

```import pandas as pd
import numpy as np ```

## DataFrame median()

The `median()` method calculates and returns the median of DataFrame/Series elements across a requested axis. In other words, the median determines the middle number(s) of the dataset.

To fully understand median from a mathematical point of view, watch this short tutorial:

The syntax for this method is as follows:

`DataFrame.median(axis=None, skipna=None, level=None, numeric_only=None, **kwargs)`

We will determine the median value(2) for our Hockey Teams for this example.

```df_teams = pd.DataFrame({'Bruins':    [4, 5,  9],
'Oilers':    [3, 6, 14],
'Leafs':     [2, 7, 11],
'Flames':    [21, 8, 7]})

result = df_teams.median(axis=0)
print(result)```
• Line  creates a DataFrame from a dictionary of lists and saves it to `df_teams`.
• Line  uses the `median()` method to calculate the median of the Teams. This output saves to the `result` variable.
• Line  outputs the result to the terminal.

Output