Pandas Slice Rows Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Simplest way to select rows is by using the iloc method which allows to access rows by their integer position. For instance, to slice a single row you can specify its index. Python import pandas as pd data = {'Name': ['John', 'Alice', 'Bob', 'Eve'], 'Age': [25, 30, 22, 35], 'Gender': ['Male', 'Female', 'Male', 'Female'], 'Salary': [50000, 55000, 40000, 70000]} df = pd.DataFrame(data) # Slice rows from position 1 to 3 (exclusive of 3) sliced_rows = df.iloc[1:3] print(sliced_rows) Output Name Age Gender Salary 1 Alice 30 Female 55000 2 Bob 22 Male 40000 In addition to the this method, there are other methods to do the same:Methid 1: Slicing Rows Using loc with ConditionsThe loc[] method allows you to slice rows based on conditions or index labels. This is useful when you want to filter rows that meet specific criteria. Python # Slice rows where Age is greater than 25 filtered_rows = df.loc[df['Age'] > 25] print(filtered_rows) Output Name Age Gender Salary 1 Alice 30 Female 55000 3 Eve 35 Female 70000 Method 2: Slicing Rows Using head and tailThe head() and tail() methods provide a quick way to slice the first or last few rows of a DataFrame. This is useful when you want to inspect the top or bottom portion of your data. Python # Get the first 3 rows top_rows = df.head(3) print(top_rows) Output Name Age Gender Salary 0 John 25 Male 50000 1 Alice 30 Female 55000 2 Bob 22 Male 40000 Python # Get the last 2 rows bottom_rows = df.tail(2) print(bottom_rows) Output Name Age Gender Salary 2 Bob 22 Male 40000 3 Eve 35 Female 70000 Comment More infoAdvertise with us Next Article Python | Pandas Index.slice_locs() A abhirajksingh Follow Improve Article Tags : Pandas AI-ML-DS Python-pandas Python pandas-basics Python pandas-io Python pandas-methods +2 More Similar Reads Split Pandas Dataframe by Rows In this article, we will explore the process of Split Pandas Dataframe by Rows. The Pandas DataFrame serves as the focal point, and throughout this discussion, we will experiment with various methods to Split Pandas Dataframe by Rows. Split Pandas DataFrame by Rows In this article, we will elucidate 3 min read Python | Pandas Series.str.slice() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas str.slice() method is used to slice substrings from a string present in Pandas 3 min read Pandas Access Rows Rows in a Pandas DataFrame represent individual records or observations and accessing them efficiently is key to data manipulation. Accessing rows in a Pandas DataFrame is fundamental for data manipulation and analysis. The most basic approach of accessing rows is using iloc function. The iloc metho 3 min read Python | Pandas Index.slice_locs() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.slice_locs() function compute slice locations for input labels. It takes 2 min read Python | Pandas Series.iloc Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas series is a One-dimensional ndarray with axis labels. The labels need not be un 2 min read Python | Pandas Series.truncate() Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Pandas Series.truncate() function is used t 2 min read Like