Pandas CRUD Operations - Python
Last Updated : 02 Jun, 2025
CRUD stands for Create, Read, Update and Delete. These are the four fundamental operations we'll use when working with data in Pandas. Whether we're creating a DataFrame from scratch, analyzing existing data, modifying values or saving our results these operations are important in Pandas.
Let’s see each operation step by step to see how they make data manipulation easy.
1. Create: Creating Dataframe
Creating a dataset in Pandas means building a DataFrame which is the main data structure in Pandas. We can create a DataFrame using various methods like reading from a file or directly creating one from Python objects like dictionaries, lists or arrays
1. Creating a DataFrame from a Dictationary
This is one of the easiest and most commonly used methods to create a dataset in Pandas
Python import pandas as pd data = { "Name": ["Ansh", "Sahil", "Ram"], "Age": [21, 20, 41], "City": ["Moradabad", "New Delhi", "Chennai"] } df = pd.DataFrame(data) print(df)
Output:
DataFrame from a Dictationary 2. Creating a DataFrame from Lists
We can also create a DataFrame by combining lists.
Python import pandas as pd names = ["Akshit", "Uday", "Sam"] ages = [25, 30, 35] cities = ["Gurugram", "New Delhi", "Chicago"] df = pd.DataFrame({ "Name": names, "Age": ages, "City": cities }) print(df)
Output:
DataFrame from Lists 3. Creating a DataFrame from a CSV File
We can also create a DataFrame by reading an external file like a CSV. Here we used the random car.csv data.
Python import pandas as pd df = pd.read_csv("/content/CAR.csv") print(df.head())
Output:
DataFrame from a CSV File2. Read: Reading Dataframe
Now that we’ve created a dataset using the Create operation, lets see by using the Read operation. This step is all about accessing and understanding our data. Pandas provides simple methods to view our dataset, check its structure and analyze its contents.
1. Viewing Rows in a DataFrame
- head(n): Displaying the First Few Rows
- tail(n): Displaying the Last Few Rows
Python import pandas as pd data = {"Name": ["Eve", "Jack", "Charlie", "Henry", "John"], "Age": [25, 30, 35, 40, 45], "City": ["NY", "LA", "SF", "Houston", "Seattle"]} df = pd.DataFrame(data) print(df.head(3)) print() print(df.tail(2))
Output:
Viewing Rows in a DataFrame2. Exploring Columns of the dataset
Python
Output:
Index(['Name', 'Age', 'City'], dtype='object')
3. Checking Data Types with dtype
We use df.types to check the particular data type of the columns we have for further operations
Python
Output:
dtype()4. Generating Descriptive Statistics with describe()
This is a very important command used in pandas to check the overall statistics for the numerical data so that we can make predictions and move easily in our data exploration.
Python
Output:
describe()3. Filtering Columns
Accessing a single Column.
Python
Output:
Single column4. Accessing Multiple columns
Python print(df[["Name", "City"]])
Output:
Multiple columns5. Finding Unique Values in a Column
Finding unique tends to provide the non-duplicates values in our columns.
Python print(df["City"].unique())
Output:
['NY' 'LA' 'SF' 'Houston' 'Seattle']
6. Filtering Rows (Conditional Filtering)
Single Condition Filtering.
Python print(df[df["Age"] > 30])
Output:
Filtering Rows7. Filtering with Multiple Conditions (AND/OR Logic)
Python print(df[(df["Age"] > 30) & (df["City"] == "SF")]) print(df[(df["Age"] > 30) | (df["City"] == "LA")])
Output:
Filtering with Multiple Conditions8. Indexing in Pandas
Integer-Based Indexing with iloc.
Python
Output:
Integer-Based Indexing9. Accessing Rows and Cells
Python
Output:
NY
10. Slicing Rows
Python
Output:
Slicing Rows11. Label-Based Indexing
Python df.set_index("Name", inplace=True)
12. Setting an Index and Accessing Rows by Labels
Python
Output:
Accessing Rows by LabelsNow, we will continue with the Update (U) and Delete (D) operations, which are important for modifying and managing data efficiently.
3. Update: Modifying Data in Pandas
Update operation allows us to modify existing data within a DataFrame. Whether we're changing specific values, updating entire columns or applying conditions to update data, Pandas makes it simple.
We will use the following dataset for the update operations.
Python import pandas as pd data = {'Name': ['Eve', 'Jack', 'Charlie', 'Henry', 'John'], 'Age': [25, 30, 35, 40, 45], 'City': ['NY', 'LA', 'SF', 'Houston', 'Seattle']} df = pd.DataFrame(data) df
Output:
Modifying Data1. Updating a Single Value: We can update a single value in a specific row and column using loc or iloc.
Python df.loc[df['Name'] == 'Jack', 'Age'] = 42 print(df)
Output:
Updating AGE2. Updating an Entire Column: We can update an entire column by assigning a new list, series or value.
Python df['City'] = ['Boston', 'Chicago', 'LA', 'Austin', 'Miami'] df
Output:
Updating an Entire Column3. Updating Based on a Condition: We can apply conditions to update values in a DataFrame.
Python df.loc[df['City'] == 'LA', 'Age'] = 31 df
Output:

4. Delete: Removing Data in Pandas
Delete operation allows us to remove data from a DataFrame. We can drop rows, columns or specific values providing flexibility in cleaning and manipulating datasets. For the delete operations we will use the dataset below.
Python import pandas as pd data = {'Name': ['Eve', 'Jack', 'Charlie', 'Henry', 'John'], 'Age': [25, 30, 35, 40, 45], 'City': ['NY', 'LA', 'SF', 'Houston', 'Seattle']} df = pd.DataFrame(data) print(df)
Output:
Removing Data in Pandas1. Delete a Column: We can delete a column using the drop() method.
Python df = df.drop('City', axis=1) print(df)
Output:
Delete a Column2. Delete a Row: Similarly we can delete rows by specifying the index.
Python df = df.drop(2, axis=0) print(df)
Output:
Delete rows by specifying index.3. Delete Rows Based on Condition: We can delete rows based on conditions.
Python df = df[df['Age'] != 35] print(df)
Output:
Delete Rows Based on Condition4. Delete entire dataset: To delete the entire DataFrame, we can use the del statement or reassign it to an empty DataFrame.
Python df = pd.DataFrame(data) del df
It will return nothing as it empty the dataset. With these basic CRUD operations we can perform data manipulation easily in complex data manipulation tasks in Pandas.
Similar Reads
Data Manipulation in Python using Pandas In Machine Learning, the model requires a dataset to operate, i.e. to train and test. But data doesnât come fully prepared and ready to use. There are discrepancies like Nan/ Null / NA values in many rows and columns. Sometimes the data set also contains some of the rows and columns which are not ev
6 min read
Pandas Cheat Sheet for Data Science in Python Pandas is a powerful and versatile library that allows you to work with data in Python. It offers a range of features and functions that make data analysis fast, easy, and efficient. Whether you are a data scientist, analyst, or engineer, Pandas can help you handle large datasets, perform complex op
15+ min read
Pandas AI: The Generative AI Python Library In the age of AI, many of our tasks have been automated especially after the launch of ChatGPT. One such tool that uses the power of ChatGPT to ease data manipulation task in Python is PandasAI. It leverages the power of ChatGPT to generate Python code and executes it. The output of the generated co
9 min read
Pandas Functions in Python: A Toolkit for Data Analysis Pandas is one of the most used libraries in Python for data science or data analysis. It can read data from CSV or Excel files, manipulate the data, and generate insights from it. Pandas can also be used to clean data, filter data, and visualize data. Whether you are a beginner or an experienced pro
6 min read
Pandas Introduction Pandas is open-source Python library which is used for data manipulation and analysis. It consist of data structures and functions to perform efficient operations on data. It is well-suited for working with tabular data such as spreadsheets or SQL tables. It is used in data science because it works
3 min read
Pandas Interview Questions Panda is a FOSS (Free and Open Source Software) Python library which provides high-performance data manipulation, in Python. It is used in various areas like data science and machine learning. Pandas is not just a library, it's an essential skill for professionals in various domains, including finan
15+ min read