Data Science Introduction
Data science means using data, programming and statistics to find useful answers and make better decisions.
What is Data Science?
Imagine Ayesha runs a bakery with three branches in Karachi. Every sale is saved by her billing software. That is a lot of data, but by itself it tells her nothing. A data scientist can use it to answer questions like:
- Which items sell most on weekends?
- Which branch is growing fastest?
- How many cakes should we bake for next Friday?
Data science mixes three skills:
| Skill | Why it is needed |
|---|---|
| Programming | To load, clean and analyse data quickly |
| Statistics and maths | To understand patterns and avoid wrong conclusions |
| Domain knowledge | To ask the right questions about the business |
The Steps of a Data Project
Most projects follow these steps:
- Ask a question: "Which product makes the most profit?"
- Collect data: from files, databases, websites or surveys
- Clean the data: fix missing values, typing mistakes and duplicates
- Explore: summarise, group and plot the data to find patterns
- Model (optional): build a machine learning model to predict something
- Communicate: share the result with charts and a clear explanation
Cleaning often takes the most time. Real data is messy.
Python Tools for Data Science
| Library | What it does |
|---|---|
| NumPy | Fast maths on arrays of numbers |
| pandas | Tables of data (DataFrames): loading, cleaning, grouping |
| matplotlib | Drawing charts |
| seaborn | Nicer statistical charts, built on matplotlib |
| scikit-learn | Machine learning models |
| Jupyter Notebook | Write code, see results and charts step by step in the browser |
Setting Up
Install Python from the official website, then install the libraries with pip:
Example
pip install pandas numpy matplotlib scikit-learn jupyterStart Jupyter Notebook:
Example
jupyter notebookA browser tab opens. Click New > Python 3 to create a notebook. Type code in a cell and press Shift + Enter to run it.
No installation? Google Colab gives you a free Jupyter notebook in the browser, with pandas and matplotlib already installed.
Plain Python vs pandas
You can analyse small data with plain Python:
Example
marks = [72, 85, 90, 64, 78]
print("Average:", sum(marks) / len(marks))
print("Highest:", max(marks))Average: 77.8 Highest: 90
But with real tables (names, cities, marks, dates), pandas is much easier. The same data as a pandas table, showing only students above 75:
Example
import pandas as pd
df = pd.DataFrame({
"student": ["Ali", "Ayesha", "Bilal", "Sana", "Hamza"],
"marks": [72, 85, 90, 64, 78],
})
print(df[df["marks"] > 75])student marks 1 Ayesha 85 2 Bilal 90 4 Hamza 78
The numbers on the left (1, 2, 4) are the index, the row labels pandas gives each row.
Data Science, AI and Machine Learning
These words are often mixed up:
- Data analysis: looking at past data to understand what happened
- Machine learning: programs that learn patterns from data to make predictions
- Artificial intelligence (AI): the wider field of making computers do "smart" tasks
- Data science: covers analysis, and often machine learning too
Exercise
Exercise
In a data science project, which step usually takes the most time?
