English:Data Science with Python

Data Science with Python
Introduction
Data Science with Python is a course for Grades 11–13 that shows you how to turn a question into evidence using data, computation, statistics, and careful communication. You will learn how to inspect datasets, clean them, explore patterns, build simple predictive models, evaluate results, and discuss ethical limits. The goal is not only to make code run, but to understand what the code means and when a conclusion is justified.

Data science combines ideas from Computer science, Statistics, Mathematics, and subject knowledge. Python is widely used because it has a clear syntax and a large ecosystem for scientific computing, data analysis, visualization, and machine learning. In this course, you will use tools such as Python, Jupyter, NumPy, Pandas, Matplotlib, and Scikit-learn.
By the end of the course, you should be able to explain a data-science workflow, write and read short Python programs, analyze tabular data with pandas, create informative visualizations, use descriptive statistics, train and evaluate a simple model, recognize common sources of bias, and communicate results with appropriate uncertainty.
What You Need Before You Start
You should be comfortable with basic arithmetic, percentages, graphs, and algebra. Previous programming experience is useful but not required. A browser-based notebook environment or a local Python installation can be used. When you work with real data, keep a record of the source, units, variable definitions, collection method, and any changes you make.

A Jupyter Notebook mixes executable code, text, formulas, tables, and charts in one document. This makes notebooks useful for data science because your reasoning can sit next to the calculations that support it.
From a Question to Evidence
A useful data-science project starts with a question that can be answered with evidence. A strong question identifies what you want to measure, which population or system you care about, and what decision or explanation the analysis should support.
A typical workflow is:
- Research question: State a focused question and define the quantities or categories you need.
- Data collection: Obtain data from a trustworthy source or design a fair collection process.
- Data cleaning: Check structure, types, missing values, duplicates, impossible values, and inconsistent labels.
- Exploratory data analysis: Use summaries and visualizations to understand distributions, relationships, and unusual cases.
- Statistical model: Build a model only when it helps answer the question or make a prediction.
- Model evaluation: Test performance on data that were not used to fit the model.
- Communication: Explain the result, uncertainty, assumptions, limitations, and possible consequences.
The workflow is iterative. A chart may reveal a data problem, an evaluation may reveal that your features are weak, or a new question may require additional data. Reproducible work keeps these revisions visible rather than hiding them.
Data, Observations, Variables, and Targets
A dataset is a structured collection of observations. In a typical table, each row represents an observation and each column represents a variable. A variable may be numerical, categorical, Boolean, text, date-time, or another structured type. A feature is an input variable used by an analysis or model. A target is the outcome a predictive model tries to estimate.
Before calculating anything, ask what each row represents. A row might represent a student, a weather station, a transaction, a city, or a measurement event. Misunderstanding the unit of observation can produce incorrect conclusions even when the code is technically correct.
Create a small data dictionary that records the variable name, meaning, data type, unit, allowed range or categories, and whether missing values are possible. This simple habit prevents many errors later.
The Python Data-Science Toolkit
Python itself provides variables, expressions, conditionals, loops, functions, modules, and data structures such as lists and dictionaries. Data science adds specialized libraries.

NumPy provides fast multidimensional arrays and numerical operations. Many scientific Python libraries build on NumPy arrays.

pandas provides the Series and DataFrame structures. A DataFrame behaves like a labeled table and supports selection, filtering, grouping, reshaping, merging, and handling missing data.

Matplotlib creates plots such as line graphs, bar charts, histograms, scatter plots, and more specialized visualizations.

scikit-learn provides consistent tools for preprocessing, model training, evaluation, and many standard machine-learning algorithms.
A First Python Data Analysis
Suppose a CSV file contains columns named score, study_hours, and course. The following example loads the file, inspects it, calculates a summary, and groups the data.
import pandas as pd
df = pd.read_csv("students.csv")
print(df.head())
df.info()
mean_score = df["score"].mean()
scores_by_course = df.groupby("course")["score"].mean()
print(mean_score)
print(scores_by_course)The expression df["score"] selects one column. The method mean() calculates its arithmetic mean. The groupby() operation separates rows by course and then computes a mean for each group. A useful analysis always connects such outputs back to the original question.
Working with DataFrames
A DataFrame is central to many Python data-analysis tasks. You should be able to inspect its size, column names, data types, and missing values before doing advanced calculations.
print(df.shape)
print(df.columns)
print(df.dtypes)
print(df.isna().sum())Selection chooses relevant rows or columns. Filtering keeps only rows that meet a condition.
selected = df[["study_hours", "score"]]
high_scores = df[df["score"] >= 80]You can also create derived variables. For example, if a dataset contains distance in meters and time in seconds, a speed variable can be calculated from those two columns. Derived variables should have clear names and units.
Grouping and aggregation help compare categories.
summary = (
df.groupby("course")["score"]
.agg(["count", "mean", "median"])
.sort_values("mean", ascending=False)
)
print(summary)
Cleaning and Preparing Data
Real datasets often contain missing values, duplicates, inconsistent spelling, mixed data types, impossible values, or measurements recorded in different units. Cleaning is not a cosmetic step. It changes the evidence on which later conclusions depend.
Use a repeatable process:
- Missing data: Determine why values are missing before deciding whether to keep, remove, or replace them.
- Duplicate data: Check whether repeated rows are genuine repeated events or accidental copies.
- Data type: Convert numbers, dates, and categories to appropriate types before calculation.
- Outlier: Investigate unusual observations rather than deleting them automatically.
- Unit of measurement: Standardize units before combining or comparing values.
- Data validation: Test rules such as allowed ranges, required columns, and category labels.
df = df.drop_duplicates()
df["score"] = pd.to_numeric(df["score"], errors="coerce")
df["course"] = df["course"].str.strip().str.title()The argument errors="coerce" converts values that cannot be interpreted as numbers into missing values. That can be useful, but you still need to inspect which values were affected and why.

A box plot summarizes a distribution using its median, quartiles, and a rule for marking points beyond the whiskers. A point beyond a whisker is not automatically an error. It may be a valid extreme observation that deserves investigation.
Exploring and Visualizing Data
Exploratory data analysis helps you understand what is present before you make a formal claim. Use several views because each one emphasizes different information.
A histogram is useful for the distribution of one numerical variable. A bar chart compares counts or summary values across categories. A scatter plot shows the relationship between two numerical variables. A box plot helps compare distributions and identify unusual values. A line graph is useful when an ordered variable such as time is central.

The classic Iris dataset shows how several measured flower features vary across three species. A scatterplot matrix makes it possible to compare pairs of variables and see which measurements provide useful separation between groups.
import matplotlib.pyplot as plt
df.plot.scatter(x="study_hours", y="score")
plt.xlabel("Study hours")
plt.ylabel("Score")
plt.title("Study time and score")
plt.show()
Why You Should Look at the Data
Summary statistics can hide important structure. Anscombe's quartet consists of four datasets with the same common summary statistics and fitted linear relationship, yet their plots look very different.

The lesson is practical: do not rely on a single statistic. Inspect distributions, create visualizations, check assumptions, and investigate influential observations.
Statistics for Data Science
Descriptive statistics summarize what is in a dataset. The mean uses every value and is sensitive to extremes. The median is the middle value after sorting and is often more robust to extreme observations. The range measures the distance from the minimum to the maximum. The interquartile range describes the middle half of the data. The standard deviation measures typical spread around the mean.
A sample is only part of a larger population or process. When you use sample results to make a broader claim, you must consider how the sample was selected. A large biased sample can still give a misleading answer.
Correlation measures the strength and direction of an association between variables. Correlation does not by itself establish causation. A relationship may be influenced by confounding variables, reverse causation, selection effects, or chance. Causal claims require stronger designs and assumptions than a simple scatter plot.
Uncertainty should be reported when it matters. Repeated samples from the same process would not give exactly the same result. Confidence intervals, resampling, and error bars are tools for describing that variation when their assumptions are appropriate.
Predictive Modeling
A predictive model learns a relationship between input features and a target from examples. In regression, the target is numerical. In classification, the target is a category. The purpose of evaluation is to estimate how well the model will perform on relevant new cases, not how perfectly it can remember the training data.
A common procedure separates data into training and test sets. The model learns from the training set and is evaluated on the test set. If you repeatedly adjust the model based on the test result, the test set stops being a clean estimate of future performance.
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_absolute_error
X = df[["study_hours"]]
y = df["score"]
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
model = LinearRegression()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
mae = mean_absolute_error(y_test, predictions)
print(mae)Mean absolute error gives the average absolute difference between predictions and true numerical values. For classification, suitable metrics may include accuracy, precision, recall, and the F1 score. The choice depends on the problem and on which kinds of mistakes matter.
A baseline is a simple reference method. A sophisticated model should be compared with a baseline so you can tell whether the additional complexity is useful.
Overfitting occurs when a model captures details or noise in its training data that do not generalize well. Cross-validation repeatedly creates training and validation splits to estimate performance more reliably and can help compare model choices.
Ethics, Privacy, Bias, and Responsible Use
Data science affects people, so technical correctness is not enough. Ask who is represented in the data, who is missing, how the data were collected, whether consent or legal permission is required, and what harms could result from an error.
Privacy means more than removing names. Combinations of location, time, age, or other attributes can sometimes identify people indirectly. Use only the data you need, restrict access when appropriate, and avoid publishing sensitive individual-level information.
Bias can enter through sampling, measurement, labels, historical inequalities, missing data, feature selection, or the way a model is deployed. A model can have good average performance while performing poorly for an important subgroup. Compare performance across relevant groups when doing so is lawful, ethical, and statistically meaningful.
A responsible report should state the purpose, data source, important preprocessing choices, evaluation method, limitations, uncertainty, and intended use. It should also identify uses for which the analysis is not reliable.
Reproducibility and Communication
A reproducible analysis allows another person to understand and rerun the essential steps. Keep raw data separate from cleaned data, write transformations in code rather than making undocumented manual edits, use meaningful variable names, record software requirements, and organize your notebook in the order of your reasoning.
A strong data story has four parts: a clear question, transparent evidence, an interpretation that does not overclaim, and a conclusion that acknowledges limitations. Good visualizations have readable labels, appropriate scales, units, and enough context for the viewer to understand what is being compared.
Before sharing a result, ask whether the chart could mislead because of a truncated axis, unequal group sizes, hidden missing data, inappropriate aggregation, or a color scale that implies more precision than the data support.
A Small End-to-End Example
Imagine that your school wants to understand whether classroom temperature is associated with student comfort ratings. You could design a short study using room-level measurements and anonymous comfort ratings.
First define the unit of observation, such as one classroom session. Record temperature, time, room identifier, occupancy, and an anonymous comfort score. Then check units, missing measurements, repeated entries, and whether data collection was consistent across rooms. Plot temperature against comfort, compare distributions across rooms or times, and calculate suitable summaries.
A predictive model could be added only if there is a real prediction goal, such as estimating comfort for a future session. Even then, a model does not prove that changing temperature alone will cause a change in comfort. Other factors such as humidity, activity, sunlight, or ventilation may matter.
This example shows the difference between description, prediction, and causation. Data science can support each goal, but the evidence needed for each one is different.
Interactive Tasks
Quiz: Test Your Knowledge
What is the main purpose of a test set in predictive modeling? (To estimate performance on unseen data) (!To increase the number of training rows) (!To remove all missing values) (!To guarantee a causal conclusion)
Which pandas structure is designed for labeled tabular data? (DataFrame) (!Dictionary only) (!Loop) (!Function)
Which graph is especially useful for examining the relationship between two numerical variables? (Scatter plot) (!Pie chart) (!Single value table) (!Word cloud)
What should you do first when you find an extreme value? (Investigate its meaning and source) (!Delete it automatically) (!Replace it with zero) (!Hide it from every graph)
What does correlation by itself establish? (Association) (!Causation) (!Random assignment) (!Perfect prediction)
Why is a baseline model useful? (It provides a reference for judging improvement) (!It guarantees the best possible model) (!It removes the need for testing) (!It converts every target into a category)
What is overfitting? (Learning training details that do not generalize well) (!Using too few column names) (!Drawing more than one chart) (!Saving data in a CSV file)
Which measure is usually more robust to extreme numerical values? (Median) (!Mean) (!Maximum) (!Range)
What does reproducibility require? (A clear record of data and analysis steps) (!A hidden sequence of manual edits) (!A chart without labels) (!A model with no documented settings)
Which practice best supports responsible data science? (Report limitations and important sources of bias) (!Assume more data always remove bias) (!Publish sensitive personal data) (!Treat every prediction as a causal explanation)
Memory Game
| DataFrame | Labeled two-dimensional table used for data analysis |
| Feature | Input variable used by a model |
| Target | Outcome that a predictive model tries to estimate |
| Median | Middle value after numerical observations are sorted |
| Outlier | Observation that lies unusually far from most others |
| Overfitting | Learning training-specific patterns that generalize poorly |
| Cross-validation | Repeated split-based evaluation used to compare model choices |
Drag and Drop
| Match the correct terms. | Topic |
|---|---|
| State the question and outcome | Problem definition |
| Check missing and inconsistent values | Data cleaning |
| Plot distributions and relationships | Exploratory analysis |
| Fit a predictive relationship | Model training |
| Measure performance on held-out cases | Model evaluation |
...
Crossword Puzzle
| Python | Which programming language is used throughout this course? |
| Pandas | Which library provides the DataFrame structure? |
| Median | Which statistic is the middle value after sorting? |
| Outlier | What do you call an unusually extreme observation? |
| Regression | Which modeling task predicts a numerical target? |
| Validation | What process checks whether a model performs well beyond its training examples? |
LearningApps
Cloze Text
Open-Ended Tasks
Easy
- Dataset diary: Choose a small public dataset and write a one-page data diary that identifies the source, unit of observation, variables, units, missing-value codes, and one question you could investigate.
- Data types audit: Import a CSV file into pandas, inspect its column types, and produce a short annotated table showing which types are appropriate and which should be changed.
- Visualization makeover: Find or create a weak chart, redesign it with clearer labels, scales, and visual choices, then explain in 150 words why your revision communicates the evidence better.
- Reproducible notebook: Create a Jupyter notebook that loads a small dataset, shows the first rows, calculates two summaries, and includes clear Markdown explanations so another learner can rerun it.
Standard
- Missing data investigation: Introduce or locate missing values in a dataset, compare at least two reasonable handling strategies, and write a short report explaining how each strategy changes the result.
- Group comparison study: Collect or use public data for two or more groups, create suitable plots and descriptive statistics, and explain what can and cannot be concluded from the comparison.
- Correlation critique: Identify a pair of correlated variables in a dataset, visualize the relationship, propose at least two possible confounding factors, and write a paragraph that avoids causal overclaiming.
- Interview a data practitioner: Interview a person who uses data in science, business, government, journalism, or another field, then summarize their workflow, quality checks, ethical concerns, and one skill they consider essential.
Advanced
- Prediction pipeline: Build a complete regression or classification notebook with preprocessing, a baseline, a train-test split, one model, an appropriate metric, and a written interpretation of the result.
- Bias audit: Examine a dataset or model for possible representation, measurement, or label bias, compare outcomes across relevant subgroups when appropriate, and propose concrete risk-reduction steps.
- Public data story: Use an open-government or scientific dataset to produce a short data story with at least three coordinated visualizations, a methods note, a limitations section, and a clear audience.
- Model comparison video: Compare two simple machine-learning methods with cross-validation, create a three-to-five-minute explanatory video showing the evidence, and justify which model you would choose for the stated purpose.
Learning Assessment
- Transfer analysis: Given an unfamiliar dataset, formulate a defensible question, identify the unit of observation and variable types, and justify a complete analysis plan before writing code.
- Cleaning decision: Analyze a dataset with missing values, duplicates, and extreme observations, defend each cleaning decision, and explain how alternative choices could change the conclusion.
- Visualization reasoning: Select an appropriate visualization for a stated question, explain why it is preferable to two alternatives, and identify at least one way the chart could still mislead.
- Model evaluation: Compare a baseline with a fitted model using a suitable metric, interpret the size and practical meaning of the difference, and diagnose one plausible source of poor generalization.
- Ethical case study: Evaluate a proposed use of student or community data, identify privacy and bias risks, and recommend safeguards that preserve useful analysis while reducing harm.
- Communication challenge: Produce a concise report for a nontechnical audience that distinguishes observed evidence, prediction, uncertainty, and causal claims without hiding important limitations.
Evidence of Learning
Knowledge: You can explain core concepts including observation, variable, feature, target, distribution, missing data, correlation, baseline, train-test split, overfitting, evaluation metric, bias, and reproducibility.
Skills: You can load, inspect, clean, transform, group, summarize, and visualize data with Python; fit and evaluate a simple model; and interpret outputs in context.
Products: Your evidence may include a reproducible notebook, data dictionary, cleaned dataset, annotated visualizations, model-evaluation table, written report, presentation, interview summary, or explanatory video.
Transfer: You can apply the workflow to an unfamiliar dataset, choose methods that fit a new question, recognize when evidence is insufficient, and communicate limitations responsibly.
OERs on the Topic
Useful open learning resources include the Python Tutorial, the pandas Getting Started Tutorials, NumPy Learn, the Matplotlib tutorials, and the scikit-learn Getting Started guide.
Linked Learning Areas
aiMOOC Projects
NEWSLernweltNOAH fragen