Python for Science

Introduction

Hi, I'm Henry! I've programmed Python professionally for a number of years. Most of my programming has been for business stuff, rather than scientific stuff. I know that Python is popular in the scientific community and now that I'm a student again I feel like doing some Python programming in a scientific context.

I created this website partly for fun, partly for documenting my own progress, and partly for having something to show, or perhaps teach, to my classmates. When I studied computer science in university I was a teacher's aide for an introductory course in Python.

Why Python?

Python is a very popular programming language. It hovers around the top of the TIOBE Programming Community index, which is an index that tries to indicate programming language popularity. At the time of writing (December, 2022) Python is number one. Python is also the fourth most popular technology on Stack Overflow's 2022 Developer Survey. I quickly searched for software developer jobs on a Swedish job board and Python was number one there as well (Java, JavaScript, C, C++ and C# were all fairly close though). Because Python is so practical, experience in Python is often desired even it it's not the main language used on the job. Learning Python is not a waste of time!

As I mentioned earlier, Python is popular in the scientific community and many nice people have worked on many nice free libraries and tools for scientific computing. Those free libraries and tools greatly improve the power of Python, by which I mean they make it easier to do hard things. If you want to solve a difficult problem in some other programming language or tool, it might take much longer because there is no suitable third-party library for the problem (or the library that does exist is of low quality). It can even be the case that your problem practically can't be solved in some tool because of inherit limitations of the tool.

Why not Excel?

I've been doing a lot of school work in Excel. In some cases Excel is really nice. Spreadsheets are cool. You can easily look at your values. You can visually structure your problem and/or solution. I have successfully used Excel for problems I would otherwise solve with pen and paper. It's nice. There are things I personally dislike about Excel though.

Excel is not free. It is proprietary software developed by Microsoft. From personal experience I can also say it's not bug-free. The user interface and the experience of using Excel annoys me more often than I think it should. I assume some of these problems are due to its age. You can't simply change the workflow and improve stuff because some users (probably many users in Excel's case) rely on its sometimes counter-intuitive behaviour.

There is one more important thing I have to mention. When it comes to power, programming is much more powerful than Excel. Programming is extremely powerful. As a software developer it's strange for me to even compare programming to Excel. The things you can do with programming is absurd. Programming has to be one of the craziest tools invented by humanity.

Anyway, Excel is an old and more than decent program (or app as people say now) for many purposes, while programming is almost limitless in comparison to Excel.

Structure of this website

Earlier I mentioned that there are many nice libraries for Python which allow us to solve hard problems more easily. We will take a look at some of them later, but I think it's better to start with the basics and try to solve problems without third-party libraries. By doing it this way I hope you will get a better understanding of why you use certain libraries. The standard library included with Python is always fine to use.

My rough plan for this website is to have three parts/units/whatever:

  1. Installing necessary tools (boring). Then quick but hopefully good introduction to Python (less boring). Then some exercises (fun!).
  2. Reading and maybe writing files. More involved and realistic computation exercises. Introduction to third-party libraries and virtual environments (sorry in advance). Creating some charts.
  3. Jupyter notebooks (these are apparently popular). Difficult exercises.

When doing research into Python libraries for science I came across a number of libraries and tools which seems worth learning about. These are the ones I want to write about on this website:

  • numpy
  • matplotlib
  • plotly
  • seaborn
  • Jupyter

I will probably find more interesting ones as I go along.

My goal is not to make you, the reader, into a programmer. Rather, I would like to focus on programming semi-useful things. I will try to go through everything you need to know to start doing useful things, which is a lot but it shouldn't be too overwhelming, and refrain from writing about unneccessary stuff (unless it's interesting).

Other resources

This is not the only website on Python programming. This is not even the only website on Python programming for science students! When I started learning Python I already had some programming experience from university, so unfortunately I don't remember my Python struggles well. I do remember following at least one MOOC. I'm not sure if the course helped or not. Programming is a practical skill. You learn by doing. There are, in my opinion, no shortcuts. If you don't write code, you won't get far. Garbage in, garbage out. Fortunately programming is pretty fun.

I have done some research into other free resources for learning Python. These have been recommended by strangers to other stranges who are trying to learn Python.

  • pythonlikeyoumeanit.com - This website was made by someone who started learning Python when they were in graduate school doing physics (so the premise is similar to this website). Me likey almost everything. There is one specific thing that is not my tempo. They suggest installing Anaconda, which is like an alternative Python installation that comes with a bunch of scientific libraries included. This does not comply with my boring philosphy. We want non-boring stuff later.
  • Automate the boring stuff with Python - This is a book, but you can read it for free on the website. I'm pretty sure this book was popular back when I started learning Python. Since it's apparently still recommended, it's probably pretty good.
  • Codecademy - Learn Python 3 - Codecademy is a website with a bunch of programming and software development courses. Some courses are free, some are not. I've used Codecademy before for other languages when I was a beginner. I might use it in the future if I want a more interactive learning experience. A downside to Codecademy is that you have to create an account.

You can find tons of resources on YouTube as well, but I haven't looked into who's good or bad. If they sound like a youtuber they are probably not worth your time.

Next: Installing