Skip to main content
TopMiniSite

Back to all posts

How to Remove Empty String In Pandas Dataframe?

Published on
4 min read
How to Remove Empty String In Pandas Dataframe? image

Best Tools to Clean Dataframes to Buy in May 2026

1 STIKKI Cleaning Putty for Electronics – Earbud & Phone Cleaning Kit with Precision Tools – Cleaner Kit & Charging Port Cleaning Compatible with iPhone & AirPod – Device Maintenance and Repair Kit

STIKKI Cleaning Putty for Electronics – Earbud & Phone Cleaning Kit with Precision Tools – Cleaner Kit & Charging Port Cleaning Compatible with iPhone & AirPod – Device Maintenance and Repair Kit

  • DEEP-CLEAN CHARGING PORTS & SPEAKERS FOR PEAK DEVICE PERFORMANCE.
  • NON-TOXIC PUTTY ENSURES SAFE CLEANING WITHOUT STICKY RESIDUE.
  • 96 USES PROVIDE UNBEATABLE VALUE FOR EVERYDAY DEVICE MAINTENANCE.
BUY & SAVE
$15.95
STIKKI Cleaning Putty for Electronics – Earbud & Phone Cleaning Kit with Precision Tools – Cleaner Kit & Charging Port Cleaning Compatible with iPhone & AirPod – Device Maintenance and Repair Kit
2 PurePort USB-C Multi-Tool Phone Cleaning Kit | Clean Repair & Restore Cell Phone Tablet & Laptop USB C Ports & Cables | Fix Unreliable & Bad Connections | Extend The Life of Your Tech Devices (Black)

PurePort USB-C Multi-Tool Phone Cleaning Kit | Clean Repair & Restore Cell Phone Tablet & Laptop USB C Ports & Cables | Fix Unreliable & Bad Connections | Extend The Life of Your Tech Devices (Black)

  • SAVE MONEY: AVOID COSTLY REPAIRS WITH PUREPORT'S CLEANING KIT.

  • ENHANCE DEVICE LIFESPAN: REVIVE YOUR TECH WITH SIMPLE, EFFECTIVE CLEANING.

  • COMPREHENSIVE CARE: CLEAN PORTS, CABLES, AND SPEAKERS FOR OPTIMAL PERFORMANCE.

BUY & SAVE
$24.99
PurePort USB-C Multi-Tool Phone Cleaning Kit | Clean Repair & Restore Cell Phone Tablet & Laptop USB C Ports & Cables | Fix Unreliable & Bad Connections | Extend The Life of Your Tech Devices (Black)
3 32 in 1 Cell Phone Cleaning kit with Charging Port Cleaner,Stylus Pen,SIM Tool,Keyboard Brush,Speaker Brush,Electronic Cleaning kit for iPhone,AirPods,iPad,Keyboard,MacBook,Earbud,Camera Lens(White)

32 in 1 Cell Phone Cleaning kit with Charging Port Cleaner,Stylus Pen,SIM Tool,Keyboard Brush,Speaker Brush,Electronic Cleaning kit for iPhone,AirPods,iPad,Keyboard,MacBook,Earbud,Camera Lens(White)

  • SIMPLIFY CLEANING WITH SPECIALIZED TOOLS FOR KEYBOARDS AND DEVICES.
  • 32 FUNCTIONAL ACCESSORIES FOR COMPLETE CLEANING, ALL IN ONE KIT.
  • EFFORTLESSLY REMOVE DUST AND DIRT FROM EVERY ELECTRONIC DEVICE.
BUY & SAVE
$9.99 $12.97
Save 23%
32 in 1 Cell Phone Cleaning kit with Charging Port Cleaner,Stylus Pen,SIM Tool,Keyboard Brush,Speaker Brush,Electronic Cleaning kit for iPhone,AirPods,iPad,Keyboard,MacBook,Earbud,Camera Lens(White)
4 Ordilend for iPhone Cleaning Kit for Charging Port Cleaner, Cleaner Kit for AirPod Multi-Tool iPhone Cleaner Repair Lightning Cable for iPad Connector Airpod Speaker Compact Portable with Storage Case

Ordilend for iPhone Cleaning Kit for Charging Port Cleaner, Cleaner Kit for AirPod Multi-Tool iPhone Cleaner Repair Lightning Cable for iPad Connector Airpod Speaker Compact Portable with Storage Case

  • REVIVE DEVICES: CLEAN CHARGING PORTS FOR OPTIMAL PERFORMANCE AND LONGEVITY!

  • RESTORE CONNECTIONS: FIX SLOW CHARGING & POOR CONNECTIONS EFFORTLESSLY!

  • SAFE & PORTABLE: COMPACT KIT ENSURES SAFE CLEANING ON-THE-GO!

BUY & SAVE
$12.99 $19.99
Save 35%
Ordilend for iPhone Cleaning Kit for Charging Port Cleaner, Cleaner Kit for AirPod Multi-Tool iPhone Cleaner Repair Lightning Cable for iPad Connector Airpod Speaker Compact Portable with Storage Case
5 ECASP Cleaner Kit for AirPod,Multi-Tool iPhone Cleaning Kit,Cell Phone Cleaning Repair & Recovery for iPhone & iPad(Type C)Charging Port,Lightning Cables&Connectors,Easy to Store & Carry Design,Black

ECASP Cleaner Kit for AirPod,Multi-Tool iPhone Cleaning Kit,Cell Phone Cleaning Repair & Recovery for iPhone & iPad(Type C)Charging Port,Lightning Cables&Connectors,Easy to Store & Carry Design,Black

  • REVIVE YOUR DEVICES: CLEAN AND REPAIR PORTS FOR OPTIMAL PERFORMANCE!
  • RESTORE CONNECTIONS: FIX CHARGING ISSUES EASILY WITH OUR CLEANING TOOLS!
  • PORTABLE & CONVENIENT: TAKE IT ANYWHERE FOR ON-THE-GO DEVICE CARE!
BUY & SAVE
$15.99 $19.99
Save 20%
ECASP Cleaner Kit for AirPod,Multi-Tool iPhone Cleaning Kit,Cell Phone Cleaning Repair & Recovery for iPhone & iPad(Type C)Charging Port,Lightning Cables&Connectors,Easy to Store & Carry Design,Black
6 Cleaning Data for Effective Data Science: Doing the other 80% of the work with Python, R, and command-line tools

Cleaning Data for Effective Data Science: Doing the other 80% of the work with Python, R, and command-line tools

BUY & SAVE
$26.49 $43.99
Save 40%
Cleaning Data for Effective Data Science: Doing the other 80% of the work with Python, R, and command-line tools
7 Keyboard Cleaning Kit Laptop Cleaner, All-in-1 Computer Screen Cleaning Brush Tool, Multi-Function PC Accessories Electronic Cleaner Kit Spray for iPhone iPad Macbook Earbud Camera Monitor with Patent

Keyboard Cleaning Kit Laptop Cleaner, All-in-1 Computer Screen Cleaning Brush Tool, Multi-Function PC Accessories Electronic Cleaner Kit Spray for iPhone iPad Macbook Earbud Camera Monitor with Patent

  • COMPREHENSIVE KIT: INCLUDES BRUSHES, CLOTHS, AND TOOLS FOR ALL DEVICES.

  • PROFESSIONAL QUALITY: DEEP CLEANS KEYBOARDS, SCREENS, AND DELICATE SURFACES.

  • PORTABLE & EASY: COMPACT DESIGN FOR ON-THE-GO CLEANING CONVENIENCE.

BUY & SAVE
$14.98 $19.98
Save 25%
Keyboard Cleaning Kit Laptop Cleaner, All-in-1 Computer Screen Cleaning Brush Tool, Multi-Function PC Accessories Electronic Cleaner Kit Spray for iPhone iPad Macbook Earbud Camera Monitor with Patent
8 Cleaning Kit for Cell Phone and Headphone Charging Port, USB C, Speaker, Cleaner Tool Fit for iPhone 16 15 14 13 Samsung, Professional Cell Phone Port Cleaning Kit for Lightning & Type C

Cleaning Kit for Cell Phone and Headphone Charging Port, USB C, Speaker, Cleaner Tool Fit for iPhone 16 15 14 13 Samsung, Professional Cell Phone Port Cleaning Kit for Lightning & Type C

  • ELIMINATE CHARGING ERRORS: CLEAN PORTS TO FIX CHARGING PAUSED ISSUES.
  • UNIVERSAL FIT FOR ALL DEVICES: WORKS FOR IPHONE & USB-C WITHOUT DAMAGE.
  • ENHANCE AUDIO QUALITY: CLEAR DUST FOR IMPROVED SOUND AND PERFORMANCE.
BUY & SAVE
$6.99
Cleaning Kit for Cell Phone and Headphone Charging Port, USB C, Speaker, Cleaner Tool Fit for iPhone 16 15 14 13 Samsung, Professional Cell Phone Port Cleaning Kit for Lightning & Type C
9 10 Pcs Charging Port Cleaner Phone Port Cleaner USB C Ports Cleaning Tool Anti-Clogging Phone Mini Brushes Phones Speaker Cleaners for Speaker and Receiver Tablet Camera Etc

10 Pcs Charging Port Cleaner Phone Port Cleaner USB C Ports Cleaning Tool Anti-Clogging Phone Mini Brushes Phones Speaker Cleaners for Speaker and Receiver Tablet Camera Etc

  • VERSATILE DESIGN: BRIGHT BLUE BRUSHES TACKLE DIRT IN ANY DIRECTION!
  • EASY-TO-USE: SIMPLY SWAP HEADS FOR EFFECTIVE, SCRATCH-FREE CLEANING.
  • AUDIO CLARITY BOOST: ENHANCE YOUR DEVICE'S PERFORMANCE AND SOUND QUALITY.
BUY & SAVE
$5.39
10 Pcs Charging Port Cleaner Phone Port Cleaner USB C Ports Cleaning Tool Anti-Clogging Phone Mini Brushes Phones Speaker Cleaners for Speaker and Receiver Tablet Camera Etc
10 Ordilend All-in-1 Keyboard Cleaner and Laptop Cleaning Kit - Professional Computer Screen-Safe Tools for MacBook and Electronics - Portable Brush Set for Gamers and Remote Professionals

Ordilend All-in-1 Keyboard Cleaner and Laptop Cleaning Kit - Professional Computer Screen-Safe Tools for MacBook and Electronics - Portable Brush Set for Gamers and Remote Professionals

  • ALL-IN-1 EFFICIENCY: REPLACE 10 TOOLS WITH OUR COMPACT CLEANING KIT.
  • SCREEN SAFE: NON-CORROSIVE FORMULA PROTECTS ALL SCREEN TYPES SAFELY.
  • PORTABLE DESIGN: SLIM PROFILE FITS EASILY IN BAGS FOR ON-THE-GO CLEANING.
BUY & SAVE
$15.98 $19.99
Save 20%
Ordilend All-in-1 Keyboard Cleaner and Laptop Cleaning Kit - Professional Computer Screen-Safe Tools for MacBook and Electronics - Portable Brush Set for Gamers and Remote Professionals
+
ONE MORE?

To remove empty strings in a pandas DataFrame, you can use the replace() method in combination with the np.nan function from the NumPy library. First, import the NumPy library by using import numpy as np. Then, you can replace empty strings with np.nan by applying the following code snippet: df.replace('', np.nan, inplace=True). This will replace all empty strings in the DataFrame named df with NaN values.

How to remove entire columns if they only contain empty strings in pandas dataframe?

You can remove entire columns from a pandas dataframe that only contain empty strings by using the following code:

import pandas as pd

Create a sample dataframe

data = {'A': ['', '', ''], 'B': ['1', '2', '3'], 'C': ['', '', '']} df = pd.DataFrame(data)

Remove columns that only contain empty strings

df = df.loc[:, (df != '').any(axis=0)]

print(df)

This code will remove columns A and C from the dataframe because they only contain empty strings. The resulting dataframe will only contain columns with at least one non-empty string.

How to remove all types of missing values, including empty strings, in pandas dataframe?

To remove all types of missing values, including empty strings, in a pandas dataframe, you can use the dropna() method.

import pandas as pd

Create a sample dataframe with missing values

data = {'A': [1, 2, None, 4, ''], 'B': ['foo', None, 'bar', '', 'baz']} df = pd.DataFrame(data)

Remove all missing values, including empty strings

df_cleaned = df.replace('', pd.NA).dropna()

print(df_cleaned)

In the above code, we first replace empty strings with pd.NA, which represents a missing value in pandas. Then, we use the dropna() method to remove rows that contain missing values. This will remove rows where any value is None or empty string.

After running this code, you will get a new dataframe df_cleaned without any missing values, including empty strings.

How to filter out rows with empty string in pandas dataframe?

You can use the replace method to replace empty strings with NaN values and then use the dropna method to filter out rows with NaN values. Here is an example:

import pandas as pd

create a sample DataFrame with empty strings

data = {'A': ['a', 'b', 'c', ''], 'B': [1, 2, 3, 4]} df = pd.DataFrame(data)

replace empty strings with NaN values

df.replace('', pd.NA, inplace=True)

drop rows with NaN values

df_filtered = df.dropna()

print(df_filtered)

This will output:

A B 0 a 1 1 b 2 2 c 3

Now, the DataFrame df_filtered contains only rows without empty strings.

How to identify empty string in pandas dataframe?

You can identify empty strings in a pandas dataframe by using the eq method along with the str.strip() method. Here's an example:

import pandas as pd

Create a sample dataframe

df = pd.DataFrame({'A': ['foo', 'bar', ' ', 'baz', '']})

Identify empty strings in column 'A'

empty_strings = df['A'].str.strip().eq('').values

Print the rows with empty strings

print(df[empty_strings])

This will print the rows in the dataframe where column 'A' contains an empty string.

How to remove empty strings without modifying the original dataframe in pandas?

You can use the df.replace() method to replace empty strings with NaN values, without modifying the original dataframe. Here is an example code snippet to do this:

import pandas as pd

Create a sample dataframe with empty strings

data = {'col1': ['a', '', 'b', 'c', ''], 'col2': ['', 'd', 'e', '', 'f']}

df = pd.DataFrame(data)

Replace empty strings with NaN values

df_cleaned = df.replace('', pd.NA, inplace=False)

Print the cleaned dataframe

print(df_cleaned)

This will create a new dataframe df_cleaned with empty strings replaced by NaN values, while leaving the original df unchanged.

How to remove empty string from specific column in pandas dataframe?

You can use the following code to remove empty strings from a specific column in a pandas DataFrame:

import pandas as pd

Create a sample DataFrame

data = {'col1': ['1', '2', '', '4', '5'], 'col2': ['a', '', 'c', 'd', 'e']} df = pd.DataFrame(data)

Replace empty strings with NaN in a specific column

df['col1'].replace('', pd.np.nan, inplace=True)

Drop rows with NaN values in the specific column

df.dropna(subset=['col1'], inplace=True)

Print the resulting DataFrame

print(df)

This code will replace empty strings in the 'col1' column with NaN and then drop rows with NaN values in that column.