How Long Did I Take to Walk Again?
Breaking a foot sucks. Recovery is slow but eventually we see the end of the tunnel.
This is a quick data visualization analysis of step counts from Apple Health data that examines my foot recovery journey after I broke it in March 2022, two days before I had a baby.
Type of data visualization: Time series, rolling average, moving average
Tools used: Python3 (pandas, datatime, seaborn, matplotlib)
What I enjoyed: comparing moving averages and how different windows smoothed the overall plot.
Full Jupyter Notebook available on my GitHub
The background story for this data project
March 3, 2022
At 38 weeks of pregnancy, I missed the last couple of steps while walking down the stairs at home. To catch myself up and NOT fall on my belly that contained a tiny living human, I landed on my left foot toes. The impact force and the weight of my body and future baby made my foot bend entirely inward and dislocated 3 of my metatarsal bones.
At the emergency room, and after a couple of x-rays, the ER doctors and orthopedic surgeons announced to me that I had a very complex foot fracture called a Lisfranc injury, a type of injury they mostly see in car crashes. The healing would take some 12 weeks and I am up for a long recovery to walk normally again. I remember that day, I was more preoccupied with my pregnancy and thought: how bad could it be? My foot will be fixed and I can move on.
How wrong was I to think so lightly!
What are Lisfranc injuries?
For people who have never heard of Lisfranc injuries (you might have if you follow NFL players), they suck big time! If you Google “worst foot injury” or “worst foot fracture” you will get the infamous Lisfranc injury as first hit.
I even asked ChatGPT:
Foot fractures that are identified as Lisfranc injuries can take different forms but they involve the midfoot and a rupture of a ligament that holds a bone of the midfoot with the metatarsal bones. You can have a rupture of that ligament without any dislocation or movement of the metatarsal bone out of its joint, or have a more severe form where the metatarsal bone moved out of the joint. Different treatments deal with different cases (if you are curious about it, there are some articles on the internet), but the rehabilitation afterward takes time. Some people manage to have their normal life back after although for some people, additional surgery is required if the ligament did not heal well and foot arch is collapsing because the bones are not stable anymore.
The word Lisfranc comes from a French doctor, Jacques Lisfranc de St Martin, who during the Napoleon wars amputated the joint that was injured after soldiers fell from their horses.
Today amputation is not necessary anymore (relief).
A long journey toward recovery
In my case, since I was pregnant, the treatment plan was unconventional. They first tried to not get me to the OR and put the bones back with very little pain killers (because pregnant). It was the most horrible pain I ever had in my life. When they realized that it would not be possible without subjecting me to intense pain (maybe triggering labor who knows??), they scheduled a first surgery to temporarily put the bones back and add wires, so my foot could deflate and I could deliver. They had an obstetrician team in the OR in case they had to deliver my baby via c-section if there were complications.
My baby was born with my husband holding the leg cast (fortunately baby is healthy and was not affected by the fall). I went back to the OR 10 days later and screws were added to my bones for more permanent fixation.
From the fall onwards, I was not allowed to put my foot down for 8 weeks.
Look at me! With a newborn in my arms in a wheelchair. (You might have guessed that I was not given any crutches — pregnant belly + crutches = unsafe)
In that time, I first almost did not walk and spent a lot of time in bed feeding my baby but we found a solution when I started to want to walk outside: I used an iWalk. This allowed me to start walking a little bit more before I was allowed to put my foot down.
After I was cleared to start putting my foot down 6 weeks after the second surgery, my daily battle of learning how to walk again started.
Now, let’s dig into the data!
Why do I want to visualize my progress toward recovery?
It is almost the first anniversary of my injury, and I thought, why not visualize my recovery progress with data? When I was a few days/weeks into my injury, I searched Google obsessively (while breastfeeding my newborn) for clues on how someone recovers from a Lisfranc injury and goes back to normal. I found very few blog posts of injured people telling the story of their recovery but it was very hard to have a visual on the progress.
What data to look at?
To look at my progress with foot recovery, I decided to use the number of steps during that time. I have tracked my steps in the past using a Fitbit but only until 2018. After that, I was involved in a study about sleep during my pregnancy and 6 months in postpartum (so from January 2022 to September 2022) using an Oura ring, however, I stopped using the Oura ring after October 2022, because it was slipping off my finger (post-partum weight loss!).
My iPhone has also been tracking my steps with the Apple Health app, obviously when I carried it. I decided that was the best tracking method that had my steps collected throughout the year.
I exported my data directly from the Apple Health app on my iPhone and received a zip file containing a file called export.xml. I do not track a lot of things in there so there is mostly my step count data.
Data preprocessing
Since the data is in a XML file, I wanted to parse and extract the data I need into a dataframe that I analyzed with Python3. Luckily, someone did it before me: To prepare my data, I used this very clear blog post from Mark Koester about preparing Apple Health data, and there is also a GitHub Repo with more resources.
In Mark’s GitHub repo, he preprocesses data by stating that the data exported from Apple Health is in UTC time and he works through changing the column startDate to his local time.
After investigating the timestamps in my dataset, it turns out that the timestamp is in the local time of where the data is exported. For example, in my case, I exported the data in Chicago, so all my steps made in Chicago don’t need to be converted from UTC time. I also traveled to different time zones between 2019 and 2023 and in this case, the timestamp is in Chicago time too.
For overall visualization, I decided not to change my timestamp to look at progress over months but will do it if I decide to take a closer look at my progress throughout the day because I traveled to Europe for three months of the time covered here. For example, how was a typical day when I was in Croatia (still healing from my foot), compared to December when I came back to Chicago?
Although I have step count data from 2016, I decided to only use the steps from 2019 (when I moved to Chicago) to today.
Data exploration and visualization
Let’s first take a look at the number of steps per day from 2019 to 2023.
In 2019, we moved to Chicago and we were living in an apartment 20-min walk from the subway. My step count was quite high even compared to the previous years.
Starting in the summer of 2019, we used a bike instead of walking to the subway to go to work, and then at the end of November, we moved to a new apartment 2 min walk from the subway. This explains the decrease in step count from June 2019 up to the beginning of the pandemic.
The obvious decline around March 2020 coincides with the beginning of confinement in Chicago. And since then I have been working a lot of the days remotely, until the end of Spring 2021. I was then working in a hybrid setting and I became pregnant in summer of 2021.
Can you guess when I broke my foot?
Moving averages
To look at my step-count trend over time after my injury, I used simple moving or rolling average technique. This technique allows to identification of big trends by smoothening the data out of small variations.
I used the rolling function from pandas to calculate my rolling averages using the step counts starting from 2019.
To identify the ideal window that will allow me to see the general trend of my recovery without the noise of small variation, I decided to plot moving averages calculated with windows of different numbers of days.
It turns out that from a window of 90 days or three months, the line smoothens (red line).
Conclusion #1: Before September 2022, I was able to walk about the same amount as before my injury (in the pandemic situation).
Next, I plotted only the period between when I broke my foot to today. A 3-month moving average helps see how I increased my walking first around the end of April and then when I was traveling in Europe between September and December.
What happens if we use a 2-week window moving average?
The 24-day moving average revealed mostly variation due to some key events, including a sharp drop in walking when I got Covid in October.
Conclusion #2: In my case, my overall foot recovery (via step count increase) can be visualized using at least a 3-month window of moving average.
I think looking at different moving averages is very interesting because I remember how hard it was to visualize my recovery; I was going through a lot of ups and downs on a daily or even weekly basis and it was very hard sometimes to even think I would be able to walk normally again. So seeing that a 3-month window is necessary to clear out the variation is really similar to the daily struggles of little sets back (variation), that overall, there is progress even if we don’t see it immediately.
For anyone reading this and going through a lower-limb injury and learning how to walk again, take it slowly but don’t feel defeated by the small setbacks because you might not see the progress before a few months, just like the moving average plot! You got this!
Average step count per day of the week
I also wanted to take a look at how a typical week looked like during that year and so I made a plot where I averaged step count for each day of the week, for every month.
Obviously, March and April were the months where I was not allowed to put my foot down, so there were very few steps done, even though I went outside a few times using my iWalk. When I was allowed to start learning how to walk (May), I remember going outside as much as I could and practicing walking in my boot, with my walker, then my cane. I had to get back to work from maternity leave beginning of June!
After then, it looks like I was walking more and more during the week (because I was going to work) and end of August, I quit my job and we traveled back to Europe so baby could meet the family. We spent time in Croatia and in Paris in October and November. My husband was working remotely during the week while I took care of baby, and we would walk mostly during the weekends.
It is very cool to see how my step count data can be explained!
Average step count per hour at different times of my recovery journey
Finally, I wanted to check what a typical day looked like at three different periods of the recovery journey: 1. right after my surgeries (March & April), 2. when I was back to work (July and August), 3. after we came back from Europe.
What was most striking is that the hourly data shows the postpartum journey as well. During the first two months, I was not walking a lot but awoken to go to the bathroom or move around to change my newborn throughout the night.
Main conclusion
My step count data definitely represent my recovery journey by showing how I walked more and more throughout the year. It also provided me a better overview of when I started walking as much as before my injury, something that I couldn’t really picture before.
Obviously, I am the expert on my own data since I know exactly what I did and how it reflects on the data. This project showed me that in any data science project, knowing the domain in which the data is generated is an essential part of being a data scientist. I am looking forward to digging into other datasets that I know less about, and seeing how doing additional research will provide additional insights than just looking at the numbers.
I hope you enjoyed this story, it was really fun looking at this data and telling my personal story at the same time.
Follow me for more stories about data science, and pivoting out of the academic world.