Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 delete rows with empty strings in Series
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?
How about df['ColumnA'][df['ColumnA'] != '']?
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How can I convert time-series data in rows into column srvmig 0 129 Apr-11-2020, 05:40 AM
Last Post: srvmig
  How to add a few empty rows into a pandas dataframe python_newbie09 2 3,523 Sep-20-2019, 08:52 AM
Last Post: python_newbie09
  Creating new rows and adding them to empty data frame kapilan15 0 469 May-31-2019, 10:19 AM
Last Post: kapilan15

Forum Jump:

Users browsing this thread: 1 Guest(s)