Skip to content

Playing with PyPlot, Pandas, and my Weight

As I trudge through the MOOC (massive online open classroom) that is DataQuest.io… I found myself thinking… what will I do with this new found knowledge. While the guided projects are great at giving real world examples… they are easy to find shortcuts by looking at the answer – see I didn’t say cheat because I don’t think it is cheating… but after a long day of work, there is only so much trial and error I want to do before “phoning for a friend” – and at the end of the day, this probably inhibits my learning… sure… but it also keeps me progressing vs getting frustrated and giving up. So, Id say its a net positive.

Well today I decided to break from the MOOC’s confines, and take what I have learned and apply it to my own data. I have been tracking my weight for the past 5+ years on a WiFi enabled scale – sometimes taking my weight daily, others weekly, and when I really don’t want to think about it maybe its only monthly! —- well that’s not quite accurate, I do check it almost daily, but sometimes don’t stay on long enough for it to register… sue me. (and probably another problem I will learn about as I progress in my data journey – lacking or poor data!)

So I looked at the data in the native application (I look at it somewhat regularly) and thought, this would be a good data set to analyze… and lets be real, while its nice and interactive on the app, it is a pretty boring display, as seen below.

So how it started. First I needed an IDE (Integrated Development Environment) – after countless searches, I picked Spyder which you can get to from here. Once I installed the IDE, I needed the data! I then downloaded my scale data and saved it in a folder I could access with my IDE as a CSV.

From there I played around, making sure I could access the data, read it, etc. That was not too bad at all… not going to lie, I felt pretty darn accomplished. Below is some of the code I used.

Next I decided to try to recreate the plot above – basically plot a simple line chart using pyplot.plot() – and what do you know, I did it! (I did trim some of the data by removing anything before 2016).

Simple Line Plot

So what do I gather from this? – well I can see my weight fluctuates a lot and this display is super boring, which I already knew. I can also see in 2020 I did not record many data points (see above) and I can see I lost a bunch of weight in 2016… but I can also see another pattern, but not quite evident from this plot (or not easily seen)

To try to pull it out, I thought coloring the data by year may help…

Looking at it… it does not really show too much different other than looking pretty cool…

What I really needed to do, what I wanted to do, was graph each year separate… can you guess what that may show? Hint, it may have to do with resolutions and holidays.

The above plots were actually pretty easy – but getting the data to display by Month on the x Axis and weight on the Y was not straight forward… I was able to get a few different renditions but they never looked quite right… I will spare you the plots, but it made me realize … THIS IS HOW YOU LEARN!

Trial, error, looking for bugs, more trial, more error. and then all of a sudden VIOLA !

Weight grouped by year – over the course of a year

So what I ended up doing, is grouping by year and then plotting weight by what day of the year it was. This would have been much easier if I had read the Pandas library features and understood datetime within it… instead I fought it for a few minutes (hours) … but at last I came up with this plot.

To me it shows a few telling things… which again I knew, but always nice to have data support the feeling!

  • 2016 – Rapid weight loss – spurred by a weight loss challenge
  • 2017- Weight increased from bottom
  • 2018 – Weight dropped… summer it flatlined… then steadily picked up
  • 2019 – same as year before
  • 2020 – same as year before

So what can I do with this info? Well if I know my weight will go up, and I don’t want it to, maybe I can proactively be on the look out for holiday excess calories?

The other thing to note, and would need to classify – is certain catalysts. Such as moving, COVID, etc. – that may be another endeavor all together so for now I will leave you with the above graphs of my weight for the world to see 🙂 and share my first test of messing with data in Python!