I am very interested in the notion of teaching high school physics with and alongside the python programming language. So much so that I’ve started www.PythonPhysics.com in an attempt to contribute to the growing field of high school computational physics education with Python. Additionally, I am the chapter leader for a Codecademy community designed to bring together teachers who are interested in teaching with code (Distinct from ‘Teaching code’). If you teach parts of your subject through a computational lens, or are interested in doing so, you can join us at https://community.codecademy.com/dubai/. Now, one of my favourite projects to date has had more to do with chemistry than it does physics…
In this project students are given access to a Google Colaboratory document that guides them through the process of creating a data frame with Pandas and exploring trends in the data with the Pyplot library. Their final challenge is to create a hypothesis that they can explore using the large dataset of elemental data that they have been given access to, and to use the python programming language to explore this data.
Part 1: Collecting the Data
For this project I did not create the dataset. Instead, the element data that was used by the students can be found and downloaded here. Soon I will be trying different methods having my students collect their own data, and these will be written up on Maker Learners as new projects (Linked to new learning).
Part 2: Creating a Google Colaboratory Notebook
The wonderful thing about Google Colaboratory is how well it plays with other Google Apps for Education. In this part I will share how I created a Google Colab notebook and created a dataframe within the notebook by pulling in data that existed on a Google Sheet. This is pretty spectacular, because it means that I can share very large datasets with my class and show them how to transform that data into all kinds of graphs and charts using python.
Step 1 – Create a Google Colab (A Google Colaboratory Notebook) using this link.
Step 2 – Once you have created a Colab, it exists within your Google Drive in an automatically generated folder called ‘Colab Notebooks’. Look for that folder now. You can move the Colab anywhere else in your drive, it won’t change the functionality of the file.
Note: One thing I noticed was that once I’d created a new Colab once this way, I could forever make a new Colab document from directly within my Google Drive.
Step 3 – The first thing that I wanted to do inside my Colab was to import the dataset that I had found on GitHub (Linked above). I did this by downloading the .csv file on GitHub and uploading it to my Google Drive. Once it was in my drive, I opened it as (and saved it as) a Google Sheet.
Step 4 – You can now import the Google Sheet data into a Colab file using a few lines of code:
from google.colab import authauth.authenticate_user()import gspreadfrom oauth2client.client import GoogleCredentialsgc = gspread.authorize(GoogleCredentials.get_application_default())
When you run that code, you’ll be given a link that you should follow to get a code from Google, giving the Colab permission to read this file (See screenshot below)
Step 5 – Once that’s done, your Colab document has the necessary permissions to read data from your Google Sheet. To create a dataframe from a specific sheet you’ll need to use the following lines of code:
Once I’d created the Colab file, I used the Google Classroom Assignment feature to distribute a copy of the Colab to each individual student (Screenshot below). This is another fantastic example of how well Colab files play with Google Apps for Education, and it really goes to show how perfect an environment Google has created for teaching Data Science to students.
Part 1: Google Sheets
The tools that we are going to use by the end of this project are rather complex if your students don’t already have some programming experience. To give my students as gentle an introduction as possible to the mindset that I wanted them to adopt during this task, we started with a more user-friendly and recognizable tool: Google Sheets.
I started by sharing this Google Sheet with my students and asking them to tab through the examples. The students were then asked to ‘Interrogate the data’ by creating a research question and identifying the correct columns of data and the correct transformations and visualizations that would allow them to construct an argument in response to the question. This was shared with the rest of the class as a short presentation followed by a Q&A style discussion. Two good examples of the presentations that lead to some wonderful discussion afterwards are here and here.
Part 2: Google Colab
I was careful to make it very clear to my students that this part was going to be challenging, sometimes confusing and maybe even seemingly impossible. I explained that this part of the learning process was as much about practicing resilience in problem solving as it was about anything else.
A very useful introduction to the tools that we would be using can be found on Kaggle here. I gave some lesson time for my students to work through the Pandas tutorial and encouraged them to translate the examples shown in this course to their own element dataframe, and to play around with the code. If anything stopped working they could restore the original version of the Colab, so play and exploration felt sufficiently risk free.
After some time to tinker with the code, I repeated the challenge given to the students using Google Sheets and asked them to think of a research question that could be tackled using the element dataframe that was now in their Google Colab.
After this was done, we took time to compare and contrast the method of using a spreadsheet vs using a programming language to work with the data. Overall, I was impressed with how much the students were able to draw from this first activity and I’m excited to tackle new problems with new data frames in future lessons.
If resources have been provided for this project, they are downloadable through the ‘Download’ button below.