/* jquery */ /* jquery accordion style*/ /* jquery init */

22 August 2016

Astro Pi Data: Python Basics

The adventures of Ed and Izzy aboard the International Space Station (ISS) have generated plenty of interest the the Raspberry Pi community and beyond. And so has the downloadable science data captured by sensors on the Astro Pi modules.

However, these CSV data files are large, even the smallest has over 100,000 rows. Consequently loading a CSV file into a spreadsheet for analysis is a long, slow process. A far more flexible option is to write some code. But how do you get started?

Here's a short Python 3 program (see below) that loads the CSV data in preparation for further analysis. Let's look at the code.

At the top we the Python module library imports followed by a few column number constants. You can add as many of these as you need. Here's the full column list.

Next we have the 'load_csv' function definition. It's this function that extracts data from the file and puts it into a two dimensional list, corresponding to the rows and columns of the spreadsheet. Then it extract the column names, from the first row, before removing this row. It returns the column names and data list.

Now we can call the 'load_csv' function with the CSV file name and store the returned column names and data list in variables.

Finally we set up a row processing loop. Here we just loop through the first 100 rows to get the humidity and timestamp data. But you could choose an alternative range or different column. Next time we'll create a data filter.

Start coding today with my Learn Python on the Raspberry Pi tutorial.