Giter Site home page Giter Site logo

hoc-climatedata's Introduction

Visualizing Climate Data: Hour of Code 2016

In this exercise, you will use the Python programming language to analyze a dataset to discover patterns, trends, and truths about weather data in our area.

What's in the box

Having downloaded this folder, you see several files:

  • README.md: This file you're reading RIGHT NOW
  • dataloader.py: A helper library that will load the data usefully for us to explore
  • explorer.py: Helper functions for you to explore and filter the data
  • visualizer.py: Where you create the visualizations of the data
  • tempdata.csv: Highs, lows, and precipitation for 90049 from 2011 - 2016. The raw data. You can look at this if you want, but we actually don't use it once it passes through the code in dataloader.py

How to read these files

explorer.py

This file defines functions that parse the data. Let's take the function higher_than():

def higher_than(data, temp):
    '''
    Returns a list of all DataPoints that had temps higher than the given temp
    '''
    return list(filter(lambda d: d.high >= temp, data))

Functions in Python are just like functions in math: they take arguments in, and use them to perform and operation. Then they return a result. In math, we use f(x) to define functions. In Python, we use the keyword def. Then, in tabbed-in lines below, we describe the operations of the function. In this case, we returned a "filtered" list of datapoints from the full dataset; the filter make sure the remaining datapoints have a high temperature that is greater than or equal to the temperature passed to the function.

See if you can similarly interpret the other functions in this file.

If you've read to the bottom, you've discovered a "broken" function: has_precip(). That's yours to implement. Using the other functions as a pattern, implement the has_precip() function so it returns only datapoints with precipitation.

dataloader.py

Although you don't have to modify this file, it is helpful to see exactly how we load our data. Simply put, we pull the raw text from tempdata.csv and turn it into a useful data structure. We call these objects DataPoints, and each one has high, low, and precip properties.

Starting on line 21, we define a function called load_data() that returns a list of DataPoint objects that we can work with. They are helpfully in chronological order.

visualizer.py

This is where we write our code. You'll see two example functions: one for printing text to the Terminal, and one for creating graphs of our data. We use pyplot to generate our graphs.

Running your code

To run the Python code, you will use Terminal. Open it up, and use the cd command to navigate to this folder. Terminal opens one level above your Downloads/ folder, so if you downloaded/unzipped this folder in your Downloads, enter:

cd Downloads/hoc-climatedata-master

If it's on your Desktop, same thing, but Desktop in lieu of Downloads.

From there, to run and re-run your code, enter:

python3 visualizer.py

hoc-climatedata's People

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.