Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Analyze City Budget Data | Data Collection and Cleaning for Journalists
Python for Journalists and Media

bookChallenge: Analyze City Budget Data

As a journalist, being able to analyze city budget data can reveal important stories about how public funds are allocated and spent. By examining which departments receive the most or least funding, you can uncover patterns, priorities, or disparities that may be newsworthy and relevant to your audience. In this challenge, you will use Python and pandas to break down a city's annual budget and summarize the findings in a clear report.

123456789101112131415
import pandas as pd # Sample data: city budget allocations by department and project data = { "Department": ["Parks", "Parks", "Police", "Fire", "Health", "Health", "Police"], "Project": ["Playground", "Gardens", "Patrol", "Fire Engines", "Clinics", "Outreach", "Equipment"], "Budget": [50000, 30000, 120000, 90000, 40000, 35000, 80000] } df = pd.DataFrame(data) # Group by department and sum the budgets department_budgets = df.groupby("Department")["Budget"].sum().reset_index() print(department_budgets)
copy

Grouping and aggregation are essential tools for journalists working with complex datasets. By grouping data by categories—such as city departments—and aggregating numerical values like budgets, you can quickly summarize large tables into meaningful insights. This approach makes it easier to spot trends, compare allocations, and identify outliers, all of which can lead to compelling stories about government priorities and spending.

Tehtävä

Swipe to start coding

You are given a DataFrame that shows a city's annual budget broken down by department. Your task is to analyze this data and create a summary report.

  • Calculate the total budget for each department by summing the "Budget" values for each department.
  • Find the department with the highest total budget.
  • Find the department with the lowest total budget.
  • Build a summary report as a string that lists each department and its total budget, and clearly states which department has the highest and lowest budgets.
  • Print the summary report at the end.

Follow these steps closely to ensure your code produces the correct results and passes all tests.

Ratkaisu

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 3
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Suggested prompts:

Can you explain how to interpret the grouped budget data?

What other types of analysis can I perform on this dataset?

How can I visualize these budget allocations for a report?

close

bookChallenge: Analyze City Budget Data

Pyyhkäise näyttääksesi valikon

As a journalist, being able to analyze city budget data can reveal important stories about how public funds are allocated and spent. By examining which departments receive the most or least funding, you can uncover patterns, priorities, or disparities that may be newsworthy and relevant to your audience. In this challenge, you will use Python and pandas to break down a city's annual budget and summarize the findings in a clear report.

123456789101112131415
import pandas as pd # Sample data: city budget allocations by department and project data = { "Department": ["Parks", "Parks", "Police", "Fire", "Health", "Health", "Police"], "Project": ["Playground", "Gardens", "Patrol", "Fire Engines", "Clinics", "Outreach", "Equipment"], "Budget": [50000, 30000, 120000, 90000, 40000, 35000, 80000] } df = pd.DataFrame(data) # Group by department and sum the budgets department_budgets = df.groupby("Department")["Budget"].sum().reset_index() print(department_budgets)
copy

Grouping and aggregation are essential tools for journalists working with complex datasets. By grouping data by categories—such as city departments—and aggregating numerical values like budgets, you can quickly summarize large tables into meaningful insights. This approach makes it easier to spot trends, compare allocations, and identify outliers, all of which can lead to compelling stories about government priorities and spending.

Tehtävä

Swipe to start coding

You are given a DataFrame that shows a city's annual budget broken down by department. Your task is to analyze this data and create a summary report.

  • Calculate the total budget for each department by summing the "Budget" values for each department.
  • Find the department with the highest total budget.
  • Find the department with the lowest total budget.
  • Build a summary report as a string that lists each department and its total budget, and clearly states which department has the highest and lowest budgets.
  • Print the summary report at the end.

Follow these steps closely to ensure your code produces the correct results and passes all tests.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 3
single

single

some-alt