DataBrighten

    pandas practice with real datasets

    6 questionswith checked answers ยท daily weather data, 2024

    groupby, idxmax and sorting on real 2024 weather and on sales orders, with code you can run. Updated 3 November 2026.

    textnumberdateyes/no

    Steps

    1. pip install pandas
    2. Download the CSV for each question into your working folder.
    3. Run each snippet; the output should match the answer.

    Questions

    try first, then open the answer

    Average 2024 temperature by city

    Code

    import pandas as pd
    df = pd.read_csv("daily-weather-2024.csv")
    print(df.groupby("city")["temp_mean_c"].mean().round(1).sort_values(ascending=False))

    Output (run on our file)

    city
    Miami          25.0
    Phoenix        24.0
    Houston        21.8
    Los Angeles    17.4
    Tokyo          16.7
    New York       13.0
    Chicago        11.8
    London         11.7
    Seattle        11.3
    Denver         10.6
    Name: temp_mean_c, dtype: float64

    File: daily-weather-2024.csv

    The hottest day in the file

    Code

    import pandas as pd
    df = pd.read_csv("daily-weather-2024.csv")
    print(df.loc[df["temp_max_c"].idxmax(), ["city", "date", "temp_max_c"]])

    Output (run on our file)

    city             Phoenix
    date          2024-07-05
    temp_max_c          46.8
    Name: 1650, dtype: object

    File: daily-weather-2024.csv

    Rainiest month in Seattle

    Code

    import pandas as pd
    df = pd.read_csv("daily-weather-2024.csv", parse_dates=["date"])
    sea = df[df["city"] == "Seattle"]
    print(sea.groupby(sea["date"].dt.month)["precip_mm"].sum().round(1).idxmax())

    Output (run on our file)

    1

    File: daily-weather-2024.csv

    Sales by region

    Code

    import pandas as pd
    s = pd.read_csv("sales-orders-1000.csv")
    print(s.groupby("region")["sales"].sum().round(2).sort_values(ascending=False))

    Output (run on our file)

    region
    South        299380.41
    Midwest      234801.89
    West         217262.68
    Northeast    204168.78
    Name: sales, dtype: float64

    File: sales-orders-1000.csv

    Profit margin by category, %

    Code

    import pandas as pd
    s = pd.read_csv("sales-orders-1000.csv")
    g = s.groupby("category")[["profit", "sales"]].sum()
    print((g["profit"] / g["sales"] * 100).round(2).sort_values(ascending=False))

    Output (run on our file)

    category
    Office Supplies    26.98
    Technology         22.32
    Furniture          21.42
    dtype: float64

    File: sales-orders-1000.csv

    Events per magnitude band

    Code

    import pandas as pd
    q = pd.read_csv("earthquakes-last-30-days.csv")
    bands = pd.cut(q["magnitude"], [2.5, 3, 4, 5, 6, 10], right=False)
    print(bands.value_counts().sort_index())

    Output (run on our file)

    magnitude
    [2.5, 3.0)     570
    [3.0, 4.0)     284
    [4.0, 5.0)     936
    [5.0, 6.0)     185
    [6.0, 10.0)     22
    Name: count, dtype: int64

    File: earthquakes-last-30-days.csv