Question: I have this list that represent Fedex tracking

```
history = ['Tuesday, March 16, 2021', '3:03 PM Hollywood, FL\nDelivered\nLeft at front door. Signature Service not requested.', '5:52 AM MIAMI, FL\nOn FedEx vehicle for delivery', '5:40 AM MIAMI, FL\nAt local FedEx facility', 'Monday, March 15, 2021', '11:42 PM OCALA, FL\nDeparted FedEx location', '10:01 PM OCALA, FL\nArrived at FedEx location', '8:28 PM OCALA, FL\nIn transit', '12:42 AM OCALA, FL\nIn transit']

```

How do I transform this list into this 3 columns dataframe
[![enter image description here](https://i.stack.imgur.com/JbeGZ.png)](https://i.stack.imgur.com/JbeGZ.png)

Answer: 
You can use [**`dateutil.parser.parse`**](https://dateutil.readthedocs.io/en/stable/parser.html) to check if an element is a valid datetime.

This should be safer than just checking if an element contains a day string (`Monday`, `Tuesday`, etc.) in case an event also contains a day string somewhere (e.g., `Delivery failed\nWill reattempt on Monday`).

```py
import dateutil.parser

history = ['Tuesday, March 16, 2021', '3:03 PM Hollywood, FL\nDelivered\nLeft at front door. Signature Service not requested.', '5:52 AM MIAMI, FL\nOn FedEx vehicle for delivery', '5:40 AM MIAMI, FL\nAt local FedEx facility', 'Monday, March 15, 2021', '11:42 PM OCALA, FL\nDeparted FedEx location', '10:01 PM OCALA, FL\nArrived at FedEx location', '8:28 PM OCALA, FL\nIn transit', '12:42 AM OCALA, FL\nIn transit']
data = []

for string in history:
    try:
        day = dateutil.parser.parse(string)
    except:
        data.append([day, *string.split('\n', maxsplit=1)])

df = pd.DataFrame(data)

#    0           1                      2
# 0  2021-03-16  3:03 PM Hollywood, FL  Delivered\nLeft at front door. Signature Servi...
# 1  2021-03-16  5:52 AM MIAMI, FL      On FedEx vehicle for delivery
# 2  2021-03-16  5:40 AM MIAMI, FL      At local FedEx facility
# 3  2021-03-15  11:42 PM OCALA, FL     Departed FedEx location
# 4  2021-03-15  10:01 PM OCALA, FL     Arrived at FedEx location
# 5  2021-03-15  8:28 PM OCALA, FL      In transit
# 6  2021-03-15  12:42 AM OCALA, FL     In transit

```
ok this is a bit hacky but might get the job done if the format is consistent, long term regex might be a better approach

```
col1 = []
col2 = []
col3 = []
for h in history:
    if 'FL' in h:
        col1.append(date)
        new_list = h.split(',')
        item2 = new_list[0][4:]
        item3 = new_list[1][4:]
        col2.append(item2.replace('\n', '. '))
        col3.append(item3.replace('\n', '. '))
    else:
        date = h

pd.DataFrame({'col1': col1,
              'col2': col2,
              'col3': col3})

```