Skip to main content
freelanceshack.com

Back to all posts

How to Remove Empty List In Pandas?

Published on
2 min read
How to Remove Empty List In Pandas? image

Best Data Cleaning Tools and Books to Buy in October 2025

1 Python Data Cleaning Cookbook: Prepare your data for analysis with pandas, NumPy, Matplotlib, scikit-learn, and OpenAI

Python Data Cleaning Cookbook: Prepare your data for analysis with pandas, NumPy, Matplotlib, scikit-learn, and OpenAI

BUY & SAVE
$37.93 $49.99
Save 24%
Python Data Cleaning Cookbook: Prepare your data for analysis with pandas, NumPy, Matplotlib, scikit-learn, and OpenAI
2 Python Data Cleaning Cookbook: Modern techniques and Python tools to detect and remove dirty data and extract key insights

Python Data Cleaning Cookbook: Modern techniques and Python tools to detect and remove dirty data and extract key insights

BUY & SAVE
$41.91 $48.99
Save 14%
Python Data Cleaning Cookbook: Modern techniques and Python tools to detect and remove dirty data and extract key insights
3 Python Tools for Data Scientists: Pocket Primer

Python Tools for Data Scientists: Pocket Primer

BUY & SAVE
$34.95
Python Tools for Data Scientists: Pocket Primer
+
ONE MORE?

To remove empty lists in pandas, you can use the dropna() method along with the apply() function. First, identify the columns that contain lists as values using the applymap(type) function. Next, drop the rows with empty lists using applymap(len) to get the length of each list and then using dropna() to remove rows where the length is 0. Finally, you can use df.reset_index(drop=True) to reset the index after removing the empty lists.

What is the function to remove empty list in pandas?

You can use the dropna() function in pandas to remove empty lists or NaN values from a DataFrame. Here is an example of how you can use this function:

import pandas as pd

Create a DataFrame with some empty lists

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

Remove empty lists from the 'col1' column

df['col1'] = df['col1'].apply(lambda x: x if x != [] else None) df.dropna(inplace=True)

print(df)

This will remove the rows with empty lists in the 'col1' column from the DataFrame.

What is the syntax to drop rows with empty list in pandas?

To drop rows with empty lists in Pandas, you can use the following syntax:

df = df[df['column_name'].apply(lambda x: len(x) > 0)]

This code snippet will filter the DataFrame df based on the length of the lists in the column named 'column_name'. Rows with empty lists will be removed from the DataFrame.

How to drop empty list in pandas dataframe?

If you want to drop rows in a pandas dataframe where all the values are NaN or empty, you can use the following code:

df.dropna(how='all', inplace=True)

This will drop any rows where all the values are NaN or empty. The inplace=True parameter will make the changes to the original dataframe.