2021-08-31

Convert date column to columns 'start' and 'end' using regex

I have a pandas DataFrame with some text and dates as strings.

pd.DataFrame({'dates': ['start 01.01.2020',                      # Only start date
                        'start 10.10.2019, end 20.20.2019', 
                        '01.05.2019',                            # Only start date
                        '01.11.2019-04.11.2019']})

I want to create two new columns; start and end. Some rows have both start and end date, but some rows only have start date. For rows with only start date, the start and end date is the same.

The resulting table should look like this:

enter image description here

So far I've tried to extract the dates using regex, but I cannot seem to figure it out.



from Recent Questions - Stack Overflow https://ift.tt/3jv4RJw
https://ift.tt/3sZNLqb

No comments:

Post a Comment