Pandas exercise 2 alternative solution in an introduction part (for beginners) as of July 2020

When I browsed through the topics, I noticed a variety of audiences from absolute beginners to professional researchers. I hope my post may suit beginners in Python (like myself too!).

Regarding this exercise (as of July 2020) where you have to plot 4 subplots on yearly returns of 4 stocks, there were lots of things coming into my head and I was thinking that this exercise cannot be solved with just a few lines of codes. When I looked into the solution, it is kind of surprised to see some methods like .groupby, .first, .last, etc. while the lecture explaining this is in part 2 on panel data using Pandas. (I remember some instance like this occurred when you have to use write ECDF class in an exercise before you know OOP, but that has already been corrected.)

Therefore, I think it might be a good idea to solve this with core Python elements to get used to Python coding logic. In practice one should do as solution does, but I tried to use only what is in part 1. The code surely is messy, but for beginners it might be good to try this without using methods in solution. Note that I always keep getting mktime error if datetime is earlier than 1970 (Unix epoch time).

It is kinda messy to put code here and indentations are messed up so I uploaded it on my github. It is the first time I put something on it as well.

1 Like