Blog

Learning Python: Data Science (Day 1)

8. April 2019 | 2 minutes read

Tags: tags

I have performed all my data parsing and evaluation with Perl as my scripting language of choice in the last years. But since all (data-)science-related fields moved to Python, it is time to increase my portfolio as well.

I used my scripts for general statistics (averaging, deviations, min/max) over hundreds of output files and also classification (“basket analysis”). So the general idea of data science is not new to me. I will, however, not rewrite my Perl scripts in Python because I probably would just convert it line by line (as far as this is possible). Therefore I will start a new, albeit non-scientific, project based on data I can generate quite easily: World of Warcraft combat logs. There is no real aim I try to achieve with this other than just learning Python basics, e.g., file handling, string/list manipulation, statistics or plotting – so I will just see where this will eventually end up.


TIL:

  • input from file
  • exception handling
  • loops over lines in a file
  • regexp with Python (as extra package… why?!)
#!/usr/bin/python
import re

inputFile = "combat.log"
playerName = "foo"
playerServer= "bar"
playerID = playerName+"-"+playerServer

#open file
try:
	inFH = open(inputFile, "rt")
except IOError:
	print ("\n\n\tERROR (input): Could not open/find",inputFile,"\n")

#loop through file
for line in inFH:
	if re.match("\d+",line)
		splitLine = line.split(",")
		print(splitLine[0]," ",splitLine[2]," ",splitLine[6]," ",splitLine[10]," ",splitLine[29])

inFH.close()

Next steps:

  • parse all events
  • store them in list (hashes in Perl)