Bring in data from an API
Use Requests to fetch a response from a web service. Read its JSON and choose the fields your script needs.
Start with the question
pandas
Read a CSV, filter a column and group related records. For an expense list, you could total each category and see where the money goes.
NumPy
Work with arrays of numbers rather than calculating one value at a time. Try an average, a range or a formula applied to every measurement.
Matplotlib
Turn your results into a chart. Compare categories with bars or use a line to follow change over time.
Try it yourself
Paste this example into a Python file on your Mac and run it. pandas groups the entries and adds up each category.
Then add a new row or change an amount. When you are comfortable with the result, try the same idea with a CSV of your own.
Illustrative example. Uses pandas, included with the Mac app.
expenses.py
import pandas as pd
expenses = pd.DataFrame({
"category": ["Food", "Travel", "Food"],
"amount": [12, 8, 18],
})
totals = expenses.groupby("category")["amount"].sum()
print(totals.to_string())Beyond spreadsheets
Use Requests to fetch a response from a web service. Read its JSON and choose the fields your script needs.
Use Beautiful Soup to inspect HTML and extract text or links from pages you are allowed to access.
Use Pillow to open an image, read its dimensions or make a resized copy. Turn a repeatable image task into Python code.
Keep the first version small
Use a small sample you can check by eye. It makes unexpected results easier to spot.
Check the calculated values in the console. Make sure they answer the question you intended.
Replace the sample with a file you want to understand. Keep an original copy as you experiment.
The data libraries are included in the Mac app.