0

I have a list that contains a list of dates along with a bunch of other info in the same element.

This is what the list looks like:

0     2020-06-25 09:04:16.295000+00:00
1     2020-06-25 08:59:11.871999+00:00
2     2020-06-25 08:57:51.039999+00:00
3     2020-06-25 08:38:45.894000+00:00
4     2020-06-25 08:37:05.439000+00:00
5     2020-06-25 08:35:33.243999+00:00
6     2020-06-22 22:51:38.947000+00:00
7     2020-06-22 22:46:00.807000+00:00
8     2020-06-22 22:44:46.937000+00:00
9     2020-06-22 22:35:14.785999+00:00
10    2020-06-22 22:27:05.739000+00:00

As you can see, there is more info than just the date. I would like to use regex and remove just the date from each element and store it into another list:

I am pretty sure that the following regex is the right keyword for pinpointing the date:

^\d{4}$\-\d{1,2}\-\d{1,2}

I am just not sure how I can properly implement this. If you can show me how to do this through pandas, it would be much appreciated.

1 Answers1

1

We usually do

df['new']=pd.to_datetime(df['col']).dt.date
BENY
  • 317,841
  • 20
  • 164
  • 234
  • Thank you for the quick response. I'm glad to say that it worked. I wasn't familiar with the to_datetime function, thanks for introducing it to me too. –  Jul 16 '20 at 00:31