Python Day 60 – index manipulation of timestamp

As the title says, I went over some manipulations of data that can be done once the timestamp is set as the index.

I learned:

To set the timestamp as the index with:

data.Timestamp = pd.to_datetime(data.Timestamp, infer_datetime_format=True)
data = data.set_index(‘Timestamp’, drop=True) 

And once we have the timestamp as the index, we can use the .loc function to slice it in different intuitive ways. For example we could use data.loc[‘date’] to get all the data on a specific date or data.loc[‘date 1′:’date 2’] to get all the data between two dates. Nifty swifty!

I also learned it’s good to .resample your data over a different unit of time so we can view more useful things with it (for instance price change over a period of three minutes or something). There are different codenames for the frequencies of the resample (D = day, W = week, B = business day, and so on).

I am still confused on:

How to run all the code in Jupyter notebooks upon opening it. And when using the .max() function it doesn’t seem like the values are sorted from max to min. How does one do that again? I know I have it in my notes I’ll have to look into it tomorrow.

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: