Often times you’ll need to know how many rows are in your dataset. Simply, it is the most foundational metric you can know about your data. Plus, you may want to find out how long your `.apply()`

function is going run. We’ll show your 6 pandas ways to count number of rows.

Pandas number of rows will tell you…drumroll…how many rows you have in your dataset. This is important to know before applying an expensive (long running) function to your dataset. It is crucial to understand while getting to know your data.

Lets go over 6 methods in order of our favorites

- DataFrame Length – len(df)
- DataFrame Info – df.info
- DataFrame__len__ – df.__len__
- DataFrame Shape – df.shape
- DF Count – df.count
- DataFrame Axis Length – (df.axes[0])

**Pseudo code**: Return the number of rows in a pandas DataFrame or Series

## Pandas Number Of Rows

### 6 Methods To Find Row Count

Below are 6 methods to find out how *tall* your your dataset is. We’ve listed them in order of our favorite to least favorite.

#### DataFrame Length

`len(df)`

First up is DataFrame Length. This super easy and *fast* function will return the length of your DataFrame. The default length is the number of rows in your dataset. This is my #1 go to function to find out row count. `len()`

come from vanilla python.

#### DataFrame Info

`df.info()`

Next is DataFrame Info. Though it is a bit slower, you’ll get more information for free. df.info() will return column names, row count, and how many non-na values you have in each row. It is useful when trying to get to know your data. I use this when I want to know row count *and* the characteristics of my columns.

#### DataFrame __len__

`df.__len__`

Fun fact, functions that start with double underscores have a short name of “**dunder**.” df.__len__ is a pass-through function that simply calls `len(df.index)`

. It is quick and easy. I don’t use it that often because 1) I have to type out extra characters and 2) the double underscores don’t look clean. But it’s fast!

#### DataFrame Shape

`df.shape[0] - To count rows`

df.shape[1] - To count columns

With DataFrame shape you’ll get the `shape`

of your DataFrame. Yes I know that sentence is palindrome. Think of shape as the height and width of your table. You’ll be returned a tuple with two values, height and width. Shape works well, but in order to get the row count you need to reference the *first item* of your tuple via “[0].”

#### DataFrame Count

`df.count()`

DataFrame Count will return the number of Non-NA values within each column. I don’t love this one because 1) it’s slower and 2) you need to do extra data work after your call .count(). Be careful, if you have NAs in your dataset, you may get confusing examples. .count() will skip these by default.

#### DataFrame Axes Length

`len(df.axes[0])`

Next up is our most verbose option – DataFrame Axes Length. Let’s break this one down. `df.axes`

will return a tuple of your two axes for rows and columns. `[0]`

will pull the first item (rows) from your tuple. Then finally `len()`

will find the length, or how many items, you have in your axis which is your row count.

Let’s look at an examples

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

### Pandas Number Of Rows¶

Counting the number of rows in your dataset is the most basic metric you'll need when getting to *know your data*. Let's run through examples to find the count of rows in your data.

We will run through 6 methods:

- len(df)
- df.info
`__len__`

- (same as len(df.index))- df.shape[0]
- df.count()
- len(df.axes[0])

But first, let's create our DataFrame

```
num_rows = 234
num_columns=5
df = pd.DataFrame(data=np.random.randint(0, 1000, (num_rows, num_columns)),
columns=["Column#{}".format(x) for x in range(num_columns)])
df.head()
```

### Method 1: len(df)¶

The most simple and easiest way to find the length of your dataframe is using vanilla python. This means calling python len() on your dataframe.

```
len(df)
```

### Method 2: df.info¶

Next is df.info. This one is nice because you get extra information for free. Unfortunately this is more for computer <> human readability. If you're going to use the number of rows in your dataframe somewhere else in your program, use len().

Notice how '234' rows is shown after 'RangeIndex: '

```
df.info()
```

### Method 3: df.**len**¶

df.`__len__`

will call len(df.index). It's quick and easy, but takes a few more characters to type which is why we don't like it.

```
df.__len__()
```

### Method 4: df.shape[0]¶

Next is df.shape which will return a tuple with the 1) row count and 2) column count of your data. Make sure to pull the row count via '[0]' on your shape.

```
print (df.shape)
print ()
print (df.shape[0])
```

### Method 5: df.count()¶

Next is df.count() which will count the number of *non-na* values within each of your columns. You'll need to interpret the data that is returned. Be careful, your data may contain NAs and output misleading results.

```
df.count()
```

### Method 6: len(df.axes[0])¶

Last up is len(df.axes[0]). This long function will return your row axis, then you must count the length of it. Let's look through it step by step.

- Return both axis (rows/columns)
- Pull our the rows
- Count the length

```
df.axes
```

```
df.axes[0]
```

```
len(df.axes[0])
```

Check out more Pandas functions on our Pandas Page