Pandas Dataframe.pop() Last Updated : 17 May, 2025 Comments Improve Suggest changes Like Article Like Report The pop() method in Pandas is used to remove a column from a DataFrame and return it as a Series. This is similar in concept to the dictionary pop() method in Python, but specifically designed for use with Pandas DataFrames. It's key features include:Removes a specified column from a DataFrame.Returns the removed column as a Pandas Series.Modifies the original DataFrame in-place.Example: Python import pandas as pd df = pd.DataFrame({ 'name': ['Alice', 'Bob'], 'age': [25, 30], 'city': ['New York', 'Paris'] }) a = df.pop('age') print(a) print(df) OutputUsing pop()Explanation: pop() removes the 'age' column and returns it as a Series. After the operation, a holds the age values and df retains only the name and city columns.Syntax of Pandas Dataframe.pop()DataFrame.pop(label)Parameters: label (str) is the name of the column to be removed.Returns: A Series containing the removed column values.Note: This method raises KeyError if the column does not exist in the DataFrame.Examples of Pandas Dataframe.pop()Example 1: This example shows that trying to pop a column which does not exist in the DataFrame will raise a KeyError. Python import pandas as pd df = pd.DataFrame({ 'product': ['Book', 'Pen'], 'price': [100, 10] }) df.pop('quantity') OutputTraceback (most recent call last): File "...", line ... df.pop('quantity') File "...", line ... raise KeyError(key) from errKeyError: 'quantity'Explanation: Since the column 'quantity' does not exist in the DataFrame, calling pop('quantity') raises a KeyError.Example 2: This example shows how you can use pop() in a loop to remove and process columns until the DataFrame is empty. Python import pandas as pd df = pd.DataFrame({ 'A': [1, 2], 'B': [3, 4], 'C': [5, 6] }) while not df.empty: col = df.columns[0] val = df.pop(col) print(col, val) OutputUsing pop()Explanation: Loop runs until the DataFrame is empty, removing the first column each time with pop(), which deletes it in-place and returns it as a Series. The column name and values are printed until all columns are processed.Example 3: This example demonstrates how to pop a column from one DataFrame and assign it to another DataFrame. Python import pandas as pd df1 = pd.DataFrame({ 'x': [10, 20], 'y': [30, 40] }) df2 = pd.DataFrame() df2['y'] = df1.pop('y') print(df1) print(df2) OutputUsing pop()Explanation: df1 is created with columns 'x' and 'y' and an empty df2 is initialized. The pop() method removes 'y' from df1 and assigns it to df2['y']. As a result, df1 contains only 'x' and df2 contains the original 'y' values. Comment More infoAdvertise with us Next Article Python | Pandas Dataframe.at[ ] K Kartikaybhutani Follow Improve Article Tags : Misc Python Python-pandas Python pandas-dataFrame Pandas-DataFrame-Methods +1 More Practice Tags : Miscpython Similar Reads Pandas DataFrame A Pandas DataFrame is a two-dimensional table-like structure in Python where data is arranged in rows and columns. Itâs one of the most commonly used tools for handling data and makes it easy to organize, analyze and manipulate data. It can store different types of data such as numbers, text and dat 10 min read Python | Pandas Dataframe.pop() The pop() method in Pandas is used to remove a column from a DataFrame and return it as a Series. This is similar in concept to the dictionary pop() method in Python, but specifically designed for use with Pandas DataFrames. It's key features include:Removes a specified column from a DataFrame.Retur 2 min read Python | Pandas Dataframe.at[ ] 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 at[] is used to return data in a dataframe at the passed location. The passed l 2 min read Python | Pandas DataFrame.values 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 o 2 min read Python | Pandas dataframe.insert() Pandas insert method allows the user to insert a column in a data frame or series(1-D Data frame). A column can also be inserted manually in a data frame by the following method, but there isn't much freedom here. For example, even column location can't be decided and hence the inserted column is al 8 min read Pandas Dataframe Index Index in pandas dataframe act as reference for each row in dataset. It can be numeric or based on specific column values. The default index is usually a RangeIndex starting from 0, but you can customize it for better data understanding. You can easily access the current index of a dataframe using th 3 min read Pandas Access DataFrame Accessing a dataframe in pandas involves retrieving, exploring, and manipulating data stored within this structure. The most basic form of accessing a DataFrame is simply referring to it by its variable name. This will display the entire DataFrame, which includes all rows and columns.Pythonimport pa 3 min read Pandas DataFrame.columns In Pandas, DataFrame.columns attribute returns the column names of a DataFrame. It gives access to the column labels, returning an Index object with the column labels that may be used for viewing, modifying, or creating new column labels for a DataFrame.Note: This attribute doesn't require any param 2 min read Python | Pandas dataframe.set_value() 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 dataframe.set_value() function put a single value at passed column and index. I 2 min read Python | Pandas DataFrame.set_index() Pandas DataFrame.set_index() method sets one or more columns as the index of a DataFrame. It can accept single or multiple column names and is useful for modifying or adding new indices to your DataFrame. By doing so, you can enhance data retrieval, indexing, and merging tasks.Syntax: DataFrame.set_ 3 min read Like