Python Day 58 – more datetime stuffs

I figured out why it wasn’t letting me subtract dates before! It was because one value was a date (year, month, day) and the other value was a date AND time (including hours, mins, seconds). The difference was really between using .datetime and .date. So I just made them both be .datetime and it worked!

I learned:

When converting dates to datetime format, you can change whether it interprets the first number as day vs month (European vs American) with the “dayfirst=True” addition. For example…

pd.to_datetime(data_name.Timestamp, infer_datetime_format=True, dayfirst=True)

I practiced a lot with formatting with .strftime. I found this cool website which lists a bunch of the variables (?) that one can use (for example %-m for number of month).

Also I read on Stackexchange that generally having back to back brackets [][] is a sign of inefficient code. So if I find myself doing that I’ll try to find a way to do it better.

I am still confused on:

Using Kernal>Restart and Run All Code does not actually run all the code as I previously thought, which means every time I open Jupyter notebook I still have to go in and manually run the code to import Pandas and assign variable values… there’s got to be a simple way around this.

I’m having trouble converting a custom dataset into usable Pandas data. In particular I’m getting an error when formatting for a month with the %-m command. It says to not use “-” even though in the documentation for .strftime I need to use -m. Je suis confuse.

These shall be problems for the tomorrow Isaac. For now I shall continue with my day.

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: