Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data preprocessing
  • Data Manipulation
  • Data Analysis using Pandas
  • EDA
  • Pandas Exercise
  • Pandas AI
  • Numpy
  • Matplotlib
  • Plotly
  • Data Analysis
  • Machine Learning
  • Data science
Open In App
Next Article:
Python | Pandas Dataframe.at[ ]
Next article icon

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) 

Output

Output
Using 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') 

Output

Traceback (most recent call last):
File "...", line ...
df.pop('quantity')
File "...", line ...
raise KeyError(key) from err
KeyError: '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) 

Output

Output
Using 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) 

Output

Output
Using 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.


Next Article
Python | Pandas Dataframe.at[ ]

K

Kartikaybhutani
Improve
Article Tags :
  • Misc
  • Python
  • Python-pandas
  • Python pandas-dataFrame
  • Pandas-DataFrame-Methods
Practice Tags :
  • Misc
  • python

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()
    DataFrame.insert() function in pandas inserts a new column into a DataFrame at a specified position. It allows you to specify the column index, column label and values to insert. This is particularly useful when you want to place a new column in a specific position instead of just appending it at th
    4 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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences