How to Get First 5 Rows of DataFrame in Python

In this article, you will learn how to get the first 5 rows of DataFrame in Python. Let’s say you have a DataFrame of colours….

The post How to Get First 5 Rows of DataFrame in Python appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli

In this article, you will learn how to get the first 5 rows of DataFrame in Python.

Let’s say you have a DataFrame of colours.

# Import pandas module
import pandas as pd

df = pd.DataFrame({"Colours": ['Red', 'Orange', 'Yellow', 'Green',
                   'Blue', 'Indigo', 'Violet']})

In order to get the first 5 rows of DataFrame, you can use the DataFrame.head() method.

# Import pandas module
import pandas as pd

df = pd.DataFrame({"Colours": ['Red', 'Orange', 'Yellow', 'Green',
                   'Blue', 'Indigo', 'Violet']})

print(df.head())

Note: The DataFrame.head() method functions by returning the first 5 rows of DataFrame by default.

The post How to Get First 5 Rows of DataFrame in Python appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli


Print Share Comment Cite Upload Translate Updates
APA

Ariessa Norramli | Sciencx (2021-02-24T10:44:35+00:00) How to Get First 5 Rows of DataFrame in Python. Retrieved from https://www.scien.cx/2021/02/24/how-to-get-first-5-rows-of-dataframe-in-python/

MLA
" » How to Get First 5 Rows of DataFrame in Python." Ariessa Norramli | Sciencx - Wednesday February 24, 2021, https://www.scien.cx/2021/02/24/how-to-get-first-5-rows-of-dataframe-in-python/
HARVARD
Ariessa Norramli | Sciencx Wednesday February 24, 2021 » How to Get First 5 Rows of DataFrame in Python., viewed ,<https://www.scien.cx/2021/02/24/how-to-get-first-5-rows-of-dataframe-in-python/>
VANCOUVER
Ariessa Norramli | Sciencx - » How to Get First 5 Rows of DataFrame in Python. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/24/how-to-get-first-5-rows-of-dataframe-in-python/
CHICAGO
" » How to Get First 5 Rows of DataFrame in Python." Ariessa Norramli | Sciencx - Accessed . https://www.scien.cx/2021/02/24/how-to-get-first-5-rows-of-dataframe-in-python/
IEEE
" » How to Get First 5 Rows of DataFrame in Python." Ariessa Norramli | Sciencx [Online]. Available: https://www.scien.cx/2021/02/24/how-to-get-first-5-rows-of-dataframe-in-python/. [Accessed: ]
rf:citation
» How to Get First 5 Rows of DataFrame in Python | Ariessa Norramli | Sciencx | https://www.scien.cx/2021/02/24/how-to-get-first-5-rows-of-dataframe-in-python/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.