The *Pandas DataFrame* has several methods concerning **Computations** and **Descriptive Stats**. When applied to a *DataFrame*, these methods evaluate the elements and return the results.

**Part 1**focuses on the DataFrame methods`abs()`

,`all()`

,`any()`

,`clip()`

,`corr()`

, and`corrwith()`

.**Part 2**focuses on the DataFrame methods`count()`

,`cov()`

,`cummax()`

,`cummin()`

,`cumprod()`

,`cumsum()`

.**Part 3**focuses on the DataFrame methods`describe()`

,`diff()`

,`eval()`

,`kurtosis()`

.**Part 4**focuses on the DataFrame methods`mad()`

,`min()`

,`max()`

,`mean()`

,`median()`

, and`mode()`

.**Part 5**focuses on the DataFrame methods`pct_change()`

,`quantile()`

,`rank()`

,`round()`

,`prod()`

, and`product()`

.**Part 6**focuses on the DataFrame methods`add_prefix()`

,`add_suffix()`

, and`align()`

.**Part 7**focuses on the DataFrame methods`at_time()`

,`between_time()`

,`drop()`

,`drop_duplicates()`

and`duplicated()`

.**Part 8**focuses on the DataFrame methods`equals()`

,`filter()`

,`first()`

,`last(), head()`

, and`tail()`

Table of Contents

## Getting Started

Remember to add the * Required Starter Code* to the top of each code snippet. This snippet will allow the code in this article to run error-free.

**Required Starter Code**

import pandas as pd import numpy as np

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

- The
`pandas`

library enables access to/from a*DataFrame*. - 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.

**Feel free to check out the correct ways of installing those libraries here:**

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

## DataFrame count()

The `count()`

method provides the count of all *non-NaN* values in a DataFrame/Series.

The syntax for this method is as follows:

DataFrame.count()

Parameters | Description |
---|---|

`axis` | If zero (0) or index is selected, apply the function to each column. Default is `None` . If one (1) is selected, apply the function to each row. |

`level` | A string specifies the level name. |

`numeric_only` | This parameter can be a float, integer, or Boolean value. By default, `False` . |

For this example, the Human Resources Dept. of Rivers Clothing wants to determine the cost of benefit coverage based on the marital status of their staff. The issue here is some data contains the NaN value.

df_staff = pd.DataFrame({'EID': [100, 101, 102, 103], 'Name': ['Micah', 'Alycia', 'Philip', 'Josiah'], 'Status': ['M', 'S', np.nan, np.nan]}) result = df_staff.count() print(result)

- Line [1-3] creates a
*DataFrame*from a Dictionary of Lists and saves it to`df_staff`

. - Line [5] uses the
`count()`

method to determine how many*non-NaN*values exist. The output saves to the`result`

variable. - Line [6] outputs the result to the terminal.

**Output:**

EID | 4 |

Name | 4 |

Status | 2 |

dtype: int64 |

## DataFrame cov()

The `cov()`

method computes pair-wise co-variances across the series of a DataFrame. This analysis determines the relationship between various measures across time. Any NaN/NULL values do not count.

The syntax for this method is as follows:

DataFrame.cov(min_periods=None, ddof=1)

Parameters | Description |
---|---|

`min_periods` | Minimum number of observations required per pair of columns to have a valid result. This parameter is an integer and is optional. |

`ddof` | This parameter is the Delta degrees of freedom. This parameter is the divisor used in calculations (`N - ddof` ), where `N` represents the number of elements. By default, the value is one (1). |

For this example, a random series of numbers generate to see the `cov()`

method in action.

np.random.seed(75) df = pd.DataFrame(np.random.randn(35, 3), columns=['Level-A', 'Level-B', 'Level-C']) result = df.cov(min_periods=12) print(result)

- Line [1] generates random numbers using the NumPy
`seed()`

method. - Line [3-4] creates a DataFrame using the NumPy
`randn()`

method and a list. This DataFrame saves to`df`

. Notice the three (3) in`randn()`

correspond to the number of columns outlined in the DataFrame. - Line [6] calls the
`cov()`

method and sets the Minimum Period to 12. - Line [7] outputs the result to the terminal.

Output:

Level-A | Level-B | Level-C | |

Level-A | 1.133852 | 0.139968 | 0.159209 |

Level-B | 0.139968 | 0.898406 | 0.540002 |

Level-C | 0.159209 | 0.540002 | 1.384775 |

## DataFrame cummax()

The `cummax()`

method returns a cumulative maximum over a DataFrame/Series axis.

The syntax for this method is as follows:

DataFrame.cummax(axis=None, skipna=True, *args, **kwargs)

Parameters | Description |
---|---|

`axis` | If zero (0) or index is selected, apply the function to each column. Default is `None` . If one (1) is selected, apply the function to each row. |

`skipna` | This parameter excludes NaN or NULL values. If a row/column contains these values, the result is NaN. By default, this is `True` . |

`*args` | Additional keywords have no effect. However, they might be compatible with NumPy. |

`**kwargs` | Additional keywords have no effect. However, they might be compatible with NumPy. |

This example displays the maximum number of wins, losses, and ties for four (4) hockey teams.

df_teams = pd.DataFrame({'Bruins': [4, 5, 9], 'Oilers': [3, 6, 10], 'Leafs': [2, 7, 11], 'Flames': [1, 8, 12]}) result = df_teams.cummax(axis=’index’) print(result)

- Line [1-4] creates a
*DataFrame*from a Dictionary of Lists and saves it to`df_teams`

. - Line [6] retrieves the maximum numbers and saves them to the
`result`

variable. - Line [7] outputs the result to the terminal.

**Output:**

Bruins | Oilers | Leafs | Flames | |

0 | 4 | 4 | 4 | 4 |

1 | 5 | 6 | 7 | 8 |

2 | 9 | 10 | 11 | 12 |

💡 **Note**: By default, Line [6] iterates over all the rows and determines the value for each column. This is equivalent to `axis=None`

or `axis=’index’`

(used in our example).

## DataFrame cummin()

The `cummin()`

method returns a cumulative minimum over a DataFrame/Series axis.

The syntax for this method is as follows:

DataFrame. cummin(axis=None, skipna=True, *args, **kwargs)

Parameters | Description |
---|---|

`axis` | If zero (0) or index is selected, apply the function to each column. Default is `None` . If one (1) is selected, apply the function to each row. |

`skipna` | This parameter excludes NaN or NULL values. If a row/column contains these values, the result is NaN. By default, this is `True` . |

`*args` | Additional keywords have no effect. However, they might be compatible with NumPy. |

`**kwargs` | Additional keywords have no effect. However, they might be compatible with NumPy. |

This example displays the minimum number of wins, losses, and ties for four (4) hockey teams.

df_teams = pd.DataFrame({'Bruins': [4, 5, 9], 'Oilers': [3, 6, 10], 'Leafs': [2, 7, 11], 'Flames': [1, 8, 12]}) result = df_teams.cummin(axis=’index’) print(result)

- Line [1-4] creates a
*DataFrame*from a Dictionary of Lists and saves it to*df_teams*. - Line [6] retrieves the minimum numbers and saves them to the result variable.
- Line [7] outputs the result to the terminal.

**Output:**

Bruins | Oilers | Leafs | Flames | |

0 | 4 | 3 | 2 | 1 |

1 | 4 | 3 | 2 | 1 |

2 | 4 | 3 | 2 | 1 |

💡 **Note**: By default, Line [6] iterates over all the rows and determines the value for each column. This is equivalent to `axis=None`

or `axis=’index’`

(used in our example).

## DataFrame cumprod()

The `cumprod()`

method returns a DataFrame/Series of the same size containing the cumulative product.

The syntax for this method is as follows:

DataFrame.cumprod(axis=None, skipna=True, *args, **kwargs)

Parameters | Description |
---|---|

`axis` | If zero (0) or index is selected, apply the function to each column. Default is `None` . If one (1) is selected, apply the function to each row. |

`skipna` | This parameter excludes NaN or NULL values. If a row/column contains these values, the result is NaN. By default, this is `True` . |

`*args` | Additional keywords have no effect. However, they might be compatible with NumPy. |

`**kwargs` | Additional keywords have no effect. However, they might be compatible with NumPy. |

This example displays the cumulative product of the Hockey Team Stats.

df_teams = pd.DataFrame({'Bruins': [4, 5, 9], 'Oilers': [3, 6, 10], 'Leafs': [2, 7, 11], 'Flames': [1, 8, 12]}) result = df_teams.cumprod(axis='index') print(result)

- Line [1-4] creates a
*DataFrame*from a Dictionary of Lists and saves it to`df_teams`

. - Line [6] retrieves the cumulative product and saves them to the
`result`

variable. - Line [7] outputs the result to the terminal.

**Output:**

Bruins | Oilers | Leafs | Flames | |

0 | 4 | 3 | 2 | 1 |

1 | 20 | 18 | 14 | 8 |

2 | 180 | 180 | 154 | 96 |

💡 **Note**: By default, Line [6] iterates over all the rows and determines the value for each column. This is equivalent to `axis=None`

or `axis=’index’`

(used in our example).

## DataFrame cumsum()

The `cumsum()`

method returns a DataFrame/Series of the same size containing the cumulative sum.

The syntax for this method is as follows:

DataFrame.cumsum(axis=None, skipna=True, *args, **kwargs)

Parameters | Description |
---|---|

`axis` | If zero (0) or index is selected, apply the function to each column. Default is `None` . If one (1) is selected, apply the function to each row. |

`skipna` | This parameter excludes NaN or NULL values. If a row/column contains these values, the result is NaN. By default, this is `True` . |

`*args` | Additional keywords have no effect. However, they might be compatible with NumPy. |

`**kwargs` | Additional keywords have no effect. However, they might be compatible with NumPy. |

This example displays the cumulative sum of the Hockey Team Stats.

df_teams = pd.DataFrame({'Bruins': [4, 5, 9], 'Oilers': [3, 6, 10], 'Leafs': [2, 7, 11], 'Flames': [1, 8, 12]}) result = df_teams.cumsum(axis='index') print(result)

- Line [1] creates a
*DataFrame*from a Dictionary of Lists and saves it to`df_teams`

. - Line [2] retrieves the cumulative sum and saves them to the
`result`

variable. - Line [3] outputs the result to the terminal.

**Output:**

Bruins | Oilers | Leafs | Flames | |

0 | 4 | 3 | 2 | 1 |

1 | 9 | 9 | 9 | 9 |

2 | 18 | 19 | 20 | 21 |

**Note**: By default, Line [6] iterates over all the rows and determines the value for each column. This is equivalent to `axis=None`

or `axis=’index’`

(used in our example).

At university, I found my love of writing and coding. Both of which I was able to use in my career.

During the past 15 years, I have held a number of positions such as:

- Corporate Technical Writer for various software programs such as Navision and Microsoft CRM
- Corporate Trainer (staff of 30+)
- Programming Teacher at a College
- Implementation Specialist for Navision and Microsoft CRM
- Senior PHP coder writing custom software online programs