Python is useful in Data Science because it lets you express data transformations clearly and use a mature ecosystem. Beginners often struggle not with syntax alone, but with deciding what to inspect, how to verify a transformation and how to keep a notebook reproducible.
Learning objectives
By the end, you should be able to write small functions, inspect tabular data, handle missing values deliberately, create a basic visualization and explain why a result is trustworthy.
Python foundations that matter
Learn variables, strings, lists, dictionaries, sets, loops, functions, exceptions and modules. Functions are especially important because they turn a long notebook into testable units with clear inputs and outputs.
def missing_rate(values):
if not values:
return 0
return sum(value is None for value in values) / len(values)
values = [10, None, 12, 8]
print(missing_rate(values))
The function counts missing values and divides by the total. The empty-list guard makes the policy explicit. The output is 0.25, meaning one of four values is missing.
NumPy and pandas
NumPy arrays support numerical operations over structured numeric data. A pandas DataFrame represents labelled rows and columns. Inspect shape, dtypes, head() and isna().sum() before analysis.
import pandas as pd
sales = pd.DataFrame({
"product": ["A", "A", "B"],
"amount": [10, 12, 7],
})
summary = sales.groupby("product", as_index=False)["amount"].sum()
print(summary)
Grouping creates one row per product and sums its amounts. Always check that the grouping level matches the question; an accidental many-to-many merge can inflate totals.
Cleaning and visualising responsibly
Record the meaning of each column, units, allowed values and missing-value policy. Do not silently convert invalid numbers to zero. Use histograms for distributions, bars for small category sets and lines for ordered time observations. A chart shows a pattern to investigate; it does not automatically prove causation.
Common mistakes
- Running notebook cells out of order or relying on hidden state.
- Using chained assignment without checking whether the intended rows changed.
- Dropping every missing row without measuring who is removed.
- Reporting a model score without a baseline, split or metric explanation.
FAQs and next step
Should I learn advanced Python first?
No. Learn enough core Python to understand functions, collections and errors, then learn pandas through a small project.
Is a notebook a complete project?
No. Add a question, data source, reproducible setup, checks, interpretation and limitations.
Next, complete the Statistics for Data Science course and publish a small EDA project using the Data Science Project Library. Further reading: Python Tutorial and pandas tutorials.