Visualize your Steam Purchase History with Python

Alexander Lacson
3 min readMay 21, 2021

--

It’s always better to manage personal expenses and if you haven’t already you should be reviewing your spending. One of the best ways to review spending is to chart it visually. There are free third-party tools that can do this for your Steam purchases. An article that explains these tools is “6 Tools to Track your Steam Stats, Deals, Spending and Play Time”. However, there are drawbacks:

  • Using these third-party tools involves exposing your data by making your Steam profile public. Sure, you can set your profile back to private after you’re done, but there’s no guarantee these tools are not saving and storing your data when you use them.
  • These tools do not know if you purchased games at a discount and will calculate what you spent based on the current price of your games. To quote the article:

“Steam Gauge can only see the current value of the games in your library, so it can’t tell you how much you’ve actually spent on a game”.

In this article, I’ll be discussing how to accurately generate a visual summary of your Steam Purchase History, without exposing your data at all.

Save Purchase History as an HTML file on your local machine

Step 1: Log into your Steam Account using a browser, not the Steam Client

Step 2: Click on your profile name on the top right then click on Account Details

Step 3: Click on View Purchase History

Step 4: At this point, you can already see your Purchase History in tabular form. Save the website that is currently in the browser as an HTML file on your computer.

Generate a Pandas DataFrame of your Purchase History

Step 1: Create a blank Python Script file using a Code Editor or IDE of your choice

Step 2: Load the data from your HTML file into a Beautiful Soup soup object. The soup object contains raw HTML.

Step 3: Create separate lists from the soup object for each of the Purchase History table columns. The soup.select() method allows us to select each column from the Steam Purchase History table which is currently in the form of HTML. The HTML file had to be inspected to determine the column labels.

Step 4: Create a Pandas DataFrame using the lists. You may want to filter out games that you have purchased and successfully refunded. Line 7 of the code removes the last two rows from the bottom of the table because in this data it represents a purchase and refund transaction of the same game.

First few rows of Steam Purchase History DataFrame

Generate Visualizations from the Data

The code below generates a bar chart of Monthly Steam Purchases using Matplotlib and Seaborn. The Pandas resample() method allows you to choose the smallest unit of time in the chart, e.g. daily, monthly, quarterly, yearly. With the following code, you have to manually specify the xposition, Line 12, of the vertical lines dividing the chart by year. You have to manually specify the xcoord, Line 15, as well as the y-coordinate, the second argument of plt.text in Line 18, of the year labels at the top of the chart.

The code below generates a Treemap of the Total Expenses by Year using Plotly.

Again using Plotly, the code below generates a Treemap of the Total Expenses by Month.

Instead of looking at your Steam Purchases in tabular form, with visualizations, you can much better comprehend how much you have been spending, and when in your life you were spending. All without making your Steam Profile data public.

--

--

Alexander Lacson
Alexander Lacson

No responses yet