0

I have a dataframe like below

id      date

1       [2000-01-01 00:00:00.0, 2018-05-24 13:19:16.987]
2       [2000-01-01 00:00:00.0]
3       [2000-01-01 00:00:00.0, 2017-10-20 08:29:48.8, 2017-10-20 08:29:48.8, 2017-10-20 08:29:48.8]

I am trying to go through and remove the date 2000-01-01 00:00:00.0 from each row.

I have tried doing df['date'] = df['date'].str.lstrip('2000-01-01 00:00:00.0, ') and all I get is every row is NaN

The expected output would be

id      date

1       [2018-05-24 13:19:16.987]
2       []
3       [2017-10-20 08:29:48.8, 2017-10-20 08:29:48.8, 2017-10-20 08:29:48.8]

Any help?

Thanks!

1 Answers1

0

Let us do explode then remove the target and agg back

df['date_new']=df.date.explode().loc[lambda x : x=!'2000-01-01 00:00:00.0'].groupby(level=0).agg(list)
BENY
  • 317,841
  • 20
  • 164
  • 234
  • I had thought of that, but unfortunately I am working with an older version of pandas where explode isn't available – Sam Kluender Apr 30 '20 at 15:28
  • @SamKluender work for older one https://stackoverflow.com/questions/53218931/how-to-unnest-explode-a-column-in-a-pandas-dataframe/53218939#53218939 – BENY Apr 30 '20 at 15:31