From ace042cd4c99570a8a7665a1ea19ae9615c2a6cd Mon Sep 17 00:00:00 2001 From: sethaferd Date: Mon, 1 Jul 2024 10:25:23 +0900 Subject: [PATCH 1/8] add .md file/entry for Pandas dataframe tail --- .../pandas/concepts/dataframe/terms/tail.md | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 content/pandas/concepts/dataframe/terms/tail.md diff --git a/content/pandas/concepts/dataframe/terms/tail.md b/content/pandas/concepts/dataframe/terms/tail.md new file mode 100644 index 00000000000..4bc369092a0 --- /dev/null +++ b/content/pandas/concepts/dataframe/terms/tail.md @@ -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. \ No newline at end of file From 34a5c1ee37a290db61c3d61afefb549d166534b8 Mon Sep 17 00:00:00 2001 From: sethaferd Date: Tue, 2 Jul 2024 08:27:57 +0900 Subject: [PATCH 2/8] added tail dir, moved tail.md in it --- content/pandas/concepts/dataframe/terms/{ => tail}/tail.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename content/pandas/concepts/dataframe/terms/{ => tail}/tail.md (100%) diff --git a/content/pandas/concepts/dataframe/terms/tail.md b/content/pandas/concepts/dataframe/terms/tail/tail.md similarity index 100% rename from content/pandas/concepts/dataframe/terms/tail.md rename to content/pandas/concepts/dataframe/terms/tail/tail.md From 49eb41b091c6df52b0557dbe11bd395639773880 Mon Sep 17 00:00:00 2001 From: Seth <78344666+sethaferd@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:33:10 +0900 Subject: [PATCH 3/8] Update content/pandas/concepts/dataframe/terms/tail/tail.md Co-authored-by: Mamta Wardhani --- content/pandas/concepts/dataframe/terms/tail/tail.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/pandas/concepts/dataframe/terms/tail/tail.md b/content/pandas/concepts/dataframe/terms/tail/tail.md index 4bc369092a0..09d9358d94d 100644 --- a/content/pandas/concepts/dataframe/terms/tail/tail.md +++ b/content/pandas/concepts/dataframe/terms/tail/tail.md @@ -1,5 +1,5 @@ --- -Title: '.copy()' +Title: '.tail()' Description: 'Returns the last n rows of a DataFrame.' Subjects: - 'Computer Science' From 4bb649cb9d5bae047a777153ed878c4abf1b1bb7 Mon Sep 17 00:00:00 2001 From: Seth <78344666+sethaferd@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:33:44 +0900 Subject: [PATCH 4/8] Update content/pandas/concepts/dataframe/terms/tail/tail.md Co-authored-by: Mamta Wardhani --- content/pandas/concepts/dataframe/terms/tail/tail.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/pandas/concepts/dataframe/terms/tail/tail.md b/content/pandas/concepts/dataframe/terms/tail/tail.md index 09d9358d94d..db316a8daac 100644 --- a/content/pandas/concepts/dataframe/terms/tail/tail.md +++ b/content/pandas/concepts/dataframe/terms/tail/tail.md @@ -13,7 +13,7 @@ CatalogContent: - '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. +In Pandas, **`.tail()`** is a method that returns the last `n` rows of a [DataFrame](https://www.codecademy.com/resources/docs/pandas/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 From f19699379ced7a2f6c37ecb6ff5c2b725fd39787 Mon Sep 17 00:00:00 2001 From: Seth <78344666+sethaferd@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:34:07 +0900 Subject: [PATCH 5/8] Update content/pandas/concepts/dataframe/terms/tail/tail.md Co-authored-by: Mamta Wardhani --- content/pandas/concepts/dataframe/terms/tail/tail.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/pandas/concepts/dataframe/terms/tail/tail.md b/content/pandas/concepts/dataframe/terms/tail/tail.md index db316a8daac..b53bcac4427 100644 --- a/content/pandas/concepts/dataframe/terms/tail/tail.md +++ b/content/pandas/concepts/dataframe/terms/tail/tail.md @@ -18,7 +18,7 @@ In Pandas, **`.tail()`** is a method that returns the last `n` rows of a [DataFr ## Syntax ```pseudo -df_tail = df.tail(n=5) +DataFrame.tail(n=5) ``` The parameter `n` specifies the number of rows to return. The default value is `n=5`. From ad71af06fb0c564166d6a53bf5e536035a022b27 Mon Sep 17 00:00:00 2001 From: sethaferd Date: Tue, 2 Jul 2024 15:58:53 +0900 Subject: [PATCH 6/8] updated syntax description, modified example --- .../concepts/dataframe/terms/tail/tail.md | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/content/pandas/concepts/dataframe/terms/tail/tail.md b/content/pandas/concepts/dataframe/terms/tail/tail.md index b53bcac4427..d661f6f1fb1 100644 --- a/content/pandas/concepts/dataframe/terms/tail/tail.md +++ b/content/pandas/concepts/dataframe/terms/tail/tail.md @@ -20,31 +20,22 @@ In Pandas, **`.tail()`** is a method that returns the last `n` rows of a [DataFr ```pseudo DataFrame.tail(n=5) ``` - -The parameter `n` specifies the number of rows to return. The default value is `n=5`. ++ **DataFrame**: The Pandas data structure on which the method is called. ++ **n**: Number of rows to return from the end of the DataFrame. The default value is 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: +# Create a sample DataFrame +data = { + 'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve', 'Frank', 'Grace'], + 'Age': [24, 30, 22, 40, 35, 23, 29] +} -```shell - A B -3 4 10 -4 5 11 -5 6 12 -``` +df = pd.DataFrame(data) -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. \ No newline at end of file +# Get the last 2 rows of the DataFrame +df.tail(2) +``` \ No newline at end of file From bb69fa756f0091690f278d683ef935e083f50158 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Tue, 2 Jul 2024 13:00:27 +0530 Subject: [PATCH 7/8] Update tail.md minor changes --- .../concepts/dataframe/terms/tail/tail.md | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/content/pandas/concepts/dataframe/terms/tail/tail.md b/content/pandas/concepts/dataframe/terms/tail/tail.md index d661f6f1fb1..b38258651c8 100644 --- a/content/pandas/concepts/dataframe/terms/tail/tail.md +++ b/content/pandas/concepts/dataframe/terms/tail/tail.md @@ -1,6 +1,6 @@ --- Title: '.tail()' -Description: 'Returns the last n rows of a DataFrame.' +Description: 'Returns the last n rows of a dataframe.' Subjects: - 'Computer Science' - 'Data Science' @@ -20,14 +20,43 @@ In Pandas, **`.tail()`** is a method that returns the last `n` rows of a [DataFr ```pseudo DataFrame.tail(n=5) ``` -+ **DataFrame**: The Pandas data structure on which the method is called. -+ **n**: Number of rows to return from the end of the DataFrame. The default value is 5. + +- `DataFrame`: The Pandas data structure on which the method is called. +- `n`: Number of rows to return from the end of the DataFrame. The default value is 5. ## Example +The example below demonstrates the use of the `.tail()` method: + ```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]}) + +# Get 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 +``` + +## Codebyte Example + +Run the code below to understand how the `.tail()` method works: + +```codebyte/python +import pandas as pd + # Create a sample DataFrame data = { 'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve', 'Frank', 'Grace'], @@ -37,5 +66,5 @@ data = { df = pd.DataFrame(data) # Get the last 2 rows of the DataFrame -df.tail(2) -``` \ No newline at end of file +print(df.tail(2)) +``` From 7fdb3c62a903b23d9e298316dda2da538bd87394 Mon Sep 17 00:00:00 2001 From: Sriparno Roy <89148144+Sriparno08@users.noreply.github.com> Date: Mon, 8 Jul 2024 19:52:56 +0530 Subject: [PATCH 8/8] Minor changes --- .../concepts/dataframe/terms/tail/tail.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/content/pandas/concepts/dataframe/terms/tail/tail.md b/content/pandas/concepts/dataframe/terms/tail/tail.md index b38258651c8..01281370e09 100644 --- a/content/pandas/concepts/dataframe/terms/tail/tail.md +++ b/content/pandas/concepts/dataframe/terms/tail/tail.md @@ -1,28 +1,29 @@ --- Title: '.tail()' -Description: 'Returns the last n rows of a dataframe.' +Description: 'Returns the last n rows of a DataFrame.' Subjects: - 'Computer Science' - 'Data Science' - - 'Web Development' Tags: + - 'Data' - 'Data Structures' + - 'Methods' - 'Pandas' CatalogContent: - 'learn-python-3' - 'paths/data-science' --- -In Pandas, **`.tail()`** is a method that returns the last `n` rows of a [DataFrame](https://www.codecademy.com/resources/docs/pandas/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. +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 -DataFrame.tail(n=5) +df.tail(n=5) ``` -- `DataFrame`: The Pandas data structure on which the method is called. -- `n`: Number of rows to return from the end of the DataFrame. The default value is 5. +- `df`: The Pandas `DataFrame` on which the method is called. +- `n`: The number of rows to return from the end of the `DataFrame`. ## Example @@ -52,15 +53,15 @@ The output of the code above will be: ## Codebyte Example -Run the code below to understand how the `.tail()` method works: +The codebyte example below shows how the `.tail()` method works: ```codebyte/python import pandas as pd # Create a sample DataFrame data = { - 'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve', 'Frank', 'Grace'], - 'Age': [24, 30, 22, 40, 35, 23, 29] + 'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve', 'Frank', 'Grace'], + 'Age': [24, 30, 22, 40, 35, 23, 29] } df = pd.DataFrame(data)