Alteryx vs. Python II

Welcome to the second part of comparing data prepping in Alteryx and in Python.
This time: Python.

Just like last time, we will use a simplified version of this data prepping challenge concerning pokemon, their combat stats and evolutions.

You can view all the relevant files on this github page:
https://github.com/Stefan-Ladwig/pandas_intro/tree/main


As this solution might not be easily understood just by looking at the code i've written, I will first explain high level what is going on and at the end present the full source code for you to read.


The first important information is that I've used the python library pandas (library meaning someone wrote code which can be used in the form of functions I can call within my code). This library is commonly used when working with tabular data within python. Whenever you read pandas.xyz, a function from the pandas library is used.

Preperations:

  • read all the data and save them in a variable (stats_data_frame & evolutions_data_frame)
  • transform into a different data type for easier access and further manipulation (stats_records & evolutions_records)
  • create a dictionary, which enables accessing a row with the name of a pokemon (stats_dict)

Main Manipulation Loop:

  • Starting in line 28 until line 71 in my code, we go through every row of evolutions_records by using a for-loop. Notice the indentation in these lines, in python this is mandatory for the programm to know where the loop ends.
  • First we check, if a pokemon has a second evolution. If not, the following lines of the loop are not executed for this element and we go to the nexrt one
  • Then we determine if the second or the third evolution is the last stage
  • Next we sum all the combat_stats to get the aggregate combat stat for the first and the last stage (by looping through the list of combat stats defined in line 8)
  • Now we calculate the increase in combat power
  • Last step of the loop is to combine the information we want in our final table into one record (one row) and add it to the list of all records

Final touch:

  • We generate a data frame from our list of records
  • Now we can write the content of the data frame into a .csv file
  • Done!

And now I present to you the script in it's entirety:


Feel free to check out my script and all the relevant files on my github and run the code yourself!
(you will of course need to install python and pandas)

Author:
Stefan Ladwig
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2025 The Information Lab