Python Forum
delete rows with empty strings in Series - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: delete rows with empty strings in Series (/thread-21559.html)



delete rows with empty strings in Series - ilcaa72 - Oct-04-2019

i have a series (column) from a DataFrame that contains empty strings, ''. i want to delete each element that is empty so this should only contain values with 'Sea' . The data is actually a panda column series but i output it as a List to see the values.

Before: ['Sea', 'Sea', '', '', '', 'Sea', 'Sea', '', '']

Whats the best way to remove these element from the series. I can use this with a list but would rather keep as series.

y = df['ColumnA'].str.strip().tolist()
y = List(filter(None, y) ) After: ['Sea', 'Sea', 'Sea', 'Sea']

how do i do the same from panda series?

i think i figured it out

df[Column 1'].replace('', np.nan).dropna()

is there a better way?


RE: delete rows with empty strings in Series - ichabod801 - Oct-04-2019

How about df['ColumnA'][df['ColumnA'] != '']?