Python | Pandas DataFrame.truncate Last Updated : 21 Feb, 2019 Comments Improve Suggest changes 13 Likes Like Report Pandas DataFrame is a two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Arithmetic operations align on both row and column labels. It can be thought of as a dict-like container for Series objects. This is the primary data structure of the Pandas. Pandas DataFrame.truncate() function is used to truncate a Series or DataFrame before and after some index value. This is a useful shorthand for boolean indexing based on index values above or below certain thresholds. Syntax: DataFrame.truncate(before=None, after=None, axis=None, copy=True) Parameter : before : Truncate all rows before this index value. after : Truncate all rows after this index value. axis : Axis to truncate. Truncates the index (rows) by default. copy : Return a copy of the truncated section. Returns : The truncated Series or DataFrame. Example #1: Use DataFrame.truncate() function to truncate some entries before and after the passed labels of the given dataframe. Python3 # importing pandas as pd import pandas as pd # Creating the DataFrame df = pd.DataFrame({'Weight':[45, 88, 56, 15, 71], 'Name':['Sam', 'Andrea', 'Alex', 'Robin', 'Kia'], 'Age':[14, 25, 55, 8, 21]}) # Create the index index_ = pd.date_range('2010-10-09 08:45', periods = 5, freq ='H') # Set the index df.index = index_ # Print the DataFrame print(df) Output : Now we will use DataFrame.truncate() function to truncate the entries before '2010-10-09 09:45:00' and after '2010-10-09 11:45:00' in the given dataframe. Python3 1== # return the truncated dataframe result = df.truncate(before = '2010-10-09 09:45:00', after = '2010-10-09 11:45:00') # Print the result print(result) Output : As we can see in the output, the DataFrame.truncate() function has successfully truncated the entries before and after the passed labels in the given dataframe. Example #2: Use DataFrame.truncate() function to truncate some entries before and after the passed labels of the given dataframe. Python3 # importing pandas as pd import pandas as pd # Creating the DataFrame df = pd.DataFrame({"A":[12, 4, 5, None, 1], "B":[7, 2, 54, 3, None], "C":[20, 16, 11, 3, 8], "D":[14, 3, None, 2, 6]}) # Create the index index_ = ['Row_1', 'Row_2', 'Row_3', 'Row_4', 'Row_5'] # Set the index df.index = index_ # Print the DataFrame print(df) Output : Now we will use DataFrame.truncate() function to truncate the entries before 'Row_3' and after 'Row_4' in the given dataframe. Python3 1== # return the truncated dataframe result = df.truncate(before = 'Row_3', after = 'Row_4') # Print the result print(result) Output : As we can see in the output, the DataFrame.truncate() function has successfully truncated the entries before and after the passed labels in the given dataframe. Create Quiz Comment S Shubham__Ranjan Follow 13 Improve S Shubham__Ranjan Follow 13 Improve Article Tags : Python Python-pandas Python pandas-dataFrame Pandas-DataFrame-Methods Explore IntroductionPandas Introduction 3 min read How to Install Pandas in Python? 5 min read How To Use Jupyter Notebook - An Ultimate Guide 5 min read Creating ObjectsCreating a Pandas DataFrame 2 min read Python Pandas Series 5 min read Creating a Pandas Series 3 min read Viewing DataPandas Dataframe/Series.head() method - Python 3 min read Pandas Dataframe/Series.tail() method - Python 3 min read Pandas DataFrame describe() Method 4 min read Selection & SlicingDealing with Rows and Columns in Pandas DataFrame 3 min read Pandas Extracting rows using .loc[] - Python 3 min read Extracting rows using Pandas .iloc[] in Python 7 min read Indexing and Selecting Data with Pandas 4 min read Boolean Indexing in Pandas 6 min read Python | Pandas DataFrame.ix[ ] 2 min read Python | Pandas Series.str.slice() 3 min read How to take column-slices of DataFrame in Pandas? 2 min read OperationsPython | Pandas.apply() 4 min read Apply function to every row in a Pandas DataFrame 3 min read Python | Pandas Series.apply() 3 min read Pandas dataframe.aggregate() | Python 2 min read Pandas DataFrame mean() Method 2 min read Python | Pandas Series.mean() 2 min read Python | Pandas dataframe.mad() 2 min read Python | Pandas Series.mad() to calculate Mean Absolute Deviation of a Series 2 min read Python | Pandas dataframe.sem() 3 min read Python | Pandas Series.value_counts() 2 min read Pandas Index.value_counts()-Python 3 min read Applying Lambda functions to Pandas Dataframe 6 min read Manipulating DataAdding New Column to Existing DataFrame in Pandas 6 min read Python | Delete rows/columns from DataFrame using Pandas.drop() 4 min read Python | Pandas DataFrame.truncate 3 min read Python | Pandas Series.truncate() 2 min read Iterating over rows and columns in Pandas DataFrame 4 min read Pandas Dataframe.sort_values() 2 min read Python | Pandas Dataframe.sort_values() | Set-2 3 min read How to add one row in existing Pandas DataFrame? 4 min read Grouping DataPandas GroupBy 4 min read Grouping Rows in pandas 2 min read Combining Multiple Columns in Pandas groupby with Dictionary 2 min read Merging, Joining, Concatenating and ComparingPython | Pandas Merging, Joining and Concatenating 8 min read Python | Pandas Series.str.cat() to concatenate string 3 min read Python - Pandas dataframe.append() 4 min read Python | Pandas Series.append() 4 min read Pandas Index.append() - Python 2 min read Python | Pandas Series.combine() 3 min read Add a row at top in pandas DataFrame 1 min read Python | Pandas str.join() to join string/list elements with passed delimiter 2 min read Join two text columns into a single column in Pandas 2 min read How To Compare Two Dataframes with Pandas compare? 5 min read How to compare the elements of the two Pandas Series? 3 min read Working with Date and TimePython | Working with date and time using Pandas 8 min read Python | Pandas Timestamp.timestamp 3 min read Python | Pandas Timestamp.now 3 min read Python | Pandas Timestamp.isoformat 2 min read Python | Pandas Timestamp.date 2 min read Python | Pandas Timestamp.replace 3 min read Pandas.to_datetime()-Python 3 min read Python | pandas.date_range() method 4 min read Working With Text DataPython | Pandas Working With Text Data 8 min read Python | Pandas Series.str.lower(), upper() and title() 4 min read Python | Pandas Series.str.replace() to replace text in a series 5 min read Python | Pandas Series.replace() 3 min read Python | Pandas Series.str.strip(), lstrip() and rstrip() 4 min read Python | Pandas tseries.offsets.DateOffset 4 min read Like