Skip to content

Instantly share code, notes, and snippets.

View jackiekazil's full-sized avatar

Jackie Kazil jackiekazil

View GitHub Profile
@jackiekazil
jackiekazil / pyusda.py
Last active December 29, 2015 18:48
Python example on how to extract data from USDA.
import requests
import sys
key = sys.argv[1]
base = 'http://api.data.gov/USDA/ERS/data/Arms/Surveys'
url = '%s?api_key=%s' % (base, key)
response = requests.get(url)
print response.json()
{
"nodes":[
{"name":"node1","group":1},
{"name":"node2","group":2},
{"name":"node3","group":2},
{"name":"node4","group":3}
],
"links":[
{"source":2,"target":1,"weight":1},
{"source":0,"target":2,"weight":3}

WiDS Python class

Getting started with Python can confusing. Hopefully, this clarifies somethings. In this class, we will go over basic concepts to give you a solid intro to the Python programming language.

  • Python 2 vs Python 3
  • python interpretor vs ipython vs code editor vs notebook
  • Anaconda vs virtualenv vs no virtualenv (Advanced intro)

Repos referenced in this class

@jackiekazil
jackiekazil / show_python_path.md
Last active June 29, 2021 18:00
How do I identify what is on my python path (where python looks to import modules)?

What is on my python path?

Knowning where python is trying to find files is important.

Let's say try to import a module and you get an Import Error.

Like this:

>>>  import foo
---------------------------------------------------------------------------
@jackiekazil
jackiekazil / rounding_decimals.md
Last active January 17, 2024 12:29
How do I round to 2 decimals in python?

How do I round to 2 decimals?

In python, you have floats and decimals that can be rounded. If you care about the accuracy of rounding, use decimal type. If you use floats, you will have issues with accuracy.

All the examples use demical types, except for the original value, which is automatically casted as a float.

To set the context of what we are working with, let's start with an original value.

Original Value