Skip to content
Tools

Weather Data Analysis with Python: Beyond the Average

Weather data analysis with Python starts with NumPy arrays and Pandas tables; I explain the input checks and reporting decisions I'd make before using the results.

Topic
Tools
Reading time
6 min
Length
1,423 words
Published
Nov 5, 2026
09:25 pm IST
In this article
  1. Where I'd use NumPy and where I'd use Pandas
  2. Defining the weather data before calculating anything
  3. Running weather data analysis with Python
  4. The checks I'd put around these examples
  5. Making a weather summary fit a production workflow
  6. What NumPy and Pandas weather averages do not solve
  7. The weather report I'd build first

For weather data analysis with Python, the concrete workflow in the source is straightforward: calculate a temperature average with NumPy, then read a CSV and calculate average humidity by city with Pandas. There is no new library release or API change here. I see this as a useful starting tutorial, but I would separate getting an answer from deciding whether that answer belongs in a production report.

The source, Trickyworld's Analyzing Weather Data with Python: NumPy and Pandas, demonstrates arrays, CSV loading, column removal, and grouped averages. I would keep those mechanics. My changes would be around the input contract, the meaning of each average, and what I let a downstream consumer claim about the result.

Where I'd use NumPy and where I'd use Pandas

I would choose NumPy for the source's first task: taking an explicit collection of temperature readings and calculating its mean. NumPy provides multidimensional arrays and mathematical operations. The tutorial uses a small temperature array, which makes the operation easy to inspect without introducing file handling or city labels.

I would choose Pandas for the second task because the question is organised around a table: which city does each humidity reading belong to? Pandas provides DataFrames with labelled axes, along with data-cleaning and aggregation tools. The source expresses that question directly by grouping the table by City and taking the mean of Humidity.

I would not turn this into a competition between the libraries. Pandas is built on NumPy, according to the source, and the examples serve different needs. My preference would be to start with the structure of the input and the question I need answered, rather than force every task through an array or every calculation through a table.

Defining the weather data before calculating anything

Before running either example, I would write down a small input contract. For temperature, I would require a unit, a city, and a stated observation period. For the humidity table, I would require an agreed meaning for each row and a consistent way of identifying cities. These are requirements I would impose, not guarantees supplied by the tutorial.

The temperature example labels its readings in Fahrenheit. I would preserve that unit in the output rather than print a bare number. I would also want to know whether the entries represent daily summaries or individual observations. I would not call something a weekly average merely because someone handed me a short list of values.

For the CSV, I would ask whoever supplies it to document the humidity unit, the period covered, and the treatment of incomplete observations. I would settle those questions before choosing a cleaning rule. My default would be to hold back a report whose inputs I cannot explain, rather than silently repair it until the script runs.

Running weather data analysis with Python

I would start with the source's temperature values as a demonstration fixture, not as observations from a named city. That gives me a small calculation I can review separately from the CSV workflow. I would keep the unit visible and avoid adding a forecast label to the output.

import numpy as np

# Demonstration values from the source, expressed in Fahrenheit.
temperatures_f = np.array([72, 69, 65, 68, 70, 74, 67])

average_temperature_f = temperatures_f.mean()
print(f"Mean of the supplied readings: {average_temperature_f} °F")

I have deliberately called this the mean of the supplied readings. I would use a more specific label only after confirming what those readings represent. This may look fussy for a tutorial, but I would rather establish the reporting vocabulary here than leave someone building the interface to guess later.

Next, I would use a CSV with the column names shown in the source. The following example assumes that weather_data.csv exists and that its city labels and humidity values have already passed the input checks I described. It is the aggregation step, not a complete ingestion pipeline.

import pandas as pd

weather_data = pd.read_csv("weather_data.csv")

average_humidity_by_city = (
    weather_data.groupby("City")["Humidity"].mean()
)

print(average_humidity_by_city)

The tutorial also removes Wind Speed and Pressure before grouping. I would leave that removal out of this particular script because my calculation already names the humidity column explicitly. If removing those columns were part of an agreed output contract, I would make that a separate, deliberate step rather than present it as necessary for calculating humidity.

The checks I'd put around these examples

  1. Confirm the question. I would write down whether I need a mean for the supplied file, a particular period, or a selected city before accepting the result.
  2. Review the input contract. I would check column names, units, city naming, and the intended meaning of a row against the supplier's description.
  3. Decide the incomplete-data policy. I would explicitly choose whether to reject, exclude, or investigate incomplete observations rather than adopt a rule without discussing its meaning.
  4. Check a small expected result. I would prepare a clearly labelled test fixture and work out its expected average independently before relying on a larger file.
  5. Review the report wording. I would make sure the heading describes the calculation actually performed, with its period and unit available to the reader.

I would keep these checks visible in a review checklist even if the first implementation were a short script. My aim would not be to turn a learning exercise into a platform. It would be to make the assumptions easy for another engineer to challenge.

Making a weather summary fit a production workflow

In my newsroom tooling work, this is the part I would examine before putting a calculated value into an editorial interface: what will the person using it think the number means? For this weather example, I would want the interface to distinguish a historical summary from a prediction. I would not ask the editor to infer that distinction from a variable name.

I would propose an output contract alongside the calculation. It would include the city, metric, unit, observation period, and a description of which observations were accepted. Those are fields I would ask the implementation to provide; they are not information the source's example already produces.

I would also decide who owns a rejected input. For an exploratory script, I might inspect the file myself. For a recurring workflow, I would want an explicit route back to the person or process supplying it. I would prefer a visible failure with an actionable explanation over publishing a number whose assumptions nobody has checked.

I would keep the original input available during review and treat the report as a derived output. That is my preferred working arrangement for investigating a disputed value. I would start with that modest boundary before considering scheduling, dashboards, or integration into another application.

What NumPy and Pandas weather averages do not solve

The source introduces a scenario involving trends, patterns, and predictions, but its weather code calculates means. I would not present those snippets as a forecasting system. If prediction were the requirement, I would ask for a separate method and a separate evaluation plan rather than stretch the meaning of the existing output.

I would be equally cautious about describing the grouped humidity result as a comparison of cities without reviewing the inputs. My acceptance criteria would require an agreed observation period and collection policy before I placed those values side by side in a report. The example itself does not establish those conditions.

There is also a cleaning trade-off I would make explicit. I might choose to exclude an incomplete observation for one report and reject the entire input for another. I would base that choice on the report's purpose and record it alongside the implementation. I would not describe either policy as universally correct just because it makes the calculation convenient.

I would skip this workflow if I only needed an official forecast; that is not what these examples implement. I would also skip building a reusable pipeline for a one-off question unless I expected to repeat the analysis. Conversely, if I already had an accepted reporting process, I would need a concrete reason to replace it with this tutorial's approach.

The weather report I'd build first

My first deliverable would be narrow: one agreed input file, one documented observation period, and a city-level humidity summary that another engineer could review. I would add the temperature calculation only if it answered a separate, explicit question. I would resist adding more metrics simply because the file happened to contain them.

I like the source's small examples because I can see the calculation without much surrounding machinery. I would preserve that simplicity, then make the assumptions less implicit. Before adding a chart or an AI-written explanation, I would ask someone to read the output and tell me what they believe it says. If their interpretation outruns the calculation, I would fix the report wording first.

Deepak Kumar

Written by

Deepak Kumar

Sr Software Engineer at India Today Group | Aaj Tak · MERN Stack · Generative AI

I build production web applications and Generative AI systems — React and Next.js on the front, Node.js and RAG pipelines behind them. I write here about what those systems actually do once real traffic hits them. Hiring a software developer in India? Here is how I work.

More on ByteMuni

ByteMuni is a developer publication: tutorials and source-checked tech news, published daily.

Read more on ByteMuni →
Message me