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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.