Python Day 59 – one step forward two steps back in datetime

I realized for my problem from yesterday with a custom datetime, if I changed ‘%-m’ to ‘%m’, the only other error was it having trouble reading the second value in the time position. So I threw in a cheeky ‘%H:00’ which is definitely wrong but it worked! And I got no errors. However…

I am still confused on:

When I actually tried passing the code through a test to see if the variables aligned with this code:

farm_dates = pd.Series([‘Oink 2020 Moo 12 Baa 18 Cluck 14:00’,
‘Oink 2020 Moo 2 Baa 3 Cluck 1:00’,
‘Oink 2004 Moo 7 Baa 9 Cluck 21:00’])

pig_latin = pd.to_datetime(farm_dates, format=’Oink %Y Moo %m Baa %d Cluck %H:00′)

print(‘Our first day is 18 and infered as %0.0f’ % farm_dates.iloc[0].day)

I got the error: ‘str’ object has no attribute ‘day’ 


I understand what that means and when I tried converting it to a ‘date’ format it didn’t work. I shall try again more tomorrow.

Additionally, I still can’t figure out how to run all the code in Jupyter notebooks. I’ve tried “Kernal -> Restart and Run All”, “Cell -> Run All”, and “Control Shift Alt Enter” which were mentioned online but it still doesn’t run it properly so the variables are all redefined and pandas imported. I’m still having to manually go through and hit enter on each cell whenever I reopen the file. This is one that has been vexing me since the very start. I swear I shall conquer thee one day!

Until that day, I bid thee adieux.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: