Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add .md file/entry for Pandas dataframe tail #4855

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add .md file/entry for Pandas dataframe tail
  • Loading branch information
sethaferd committed Jul 1, 2024
commit ace042cd4c99570a8a7665a1ea19ae9615c2a6cd
50 changes: 50 additions & 0 deletions content/pandas/concepts/dataframe/terms/tail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
Title: '.copy()'
Description: 'Returns the last n rows of a DataFrame.'
Subjects:
- 'Computer Science'
- 'Data Science'
- 'Web Development'
Tags:
- 'Data Structures'
- 'Pandas'
CatalogContent:
- 'learn-python-3'
- 'paths/data-science'
---

In Pandas, **`.tail()`** is a method that returns the last n rows of a DataFrame. By default, it returns the last 5 rows, but the number of rows can be adjusted by passing an integer argument to the method.

## Syntax

```pseudo
df_tail = df.tail(n=5)
```

The parameter `n` specifies the number of rows to return. The default value is `n=5`.

## Example

```py
import pandas as pd

# Create a DataFrame
df = pd.DataFrame({'A': [1, 2, 3, 4, 5, 6], 'B': [7, 8, 9, 10, 11, 12]})

# View the last 3 rows of the DataFrame
last_three_rows = df.tail(3)

# Print the last 3 rows
print(last_three_rows)
```

The output of the code above will be:

```shell
A B
3 4 10
4 5 11
5 6 12
```

By using the `.tail()` method, the end of a DataFrame can be previewed, which can be useful for inspecting the most recent data in a dataset.