# Python for Analysts

> The Python you actually need for analysis: types, collections, control flow, functions, files and packages. Free notes, key concepts, resources and a mini...

Canonical: https://www.internhack.in/roadmaps/tracks/data-analyst/python-for-analysis
Last updated: 2026-11-28

The Python you actually need for analysis: types, collections, control flow, functions, files and packages.

Beginner · about 15 hours · difficulty 2/5

Python lets you handle data too big or messy for spreadsheets, repeat analyses automatically, and use a huge ecosystem of statistics and visualisation libraries. You do not need to become a software engineer; you need a solid working core.

### The core you need

- **Values and types**: int, float, str, bool, None. f-strings for formatting: `f"{rate:.1%}"`.
- **Collections**: lists, dicts, tuples, sets. Dicts map keys to values and show up everywhere, including JSON from APIs.
- **Control flow**: `if`, `for`, `while`, and list or dict comprehensions.
- **Functions**: parameters, return values, default arguments. Wrap repeated logic in a function.
- **Files and paths**: reading CSV and JSON, `pathlib` for paths.
- **Errors**: read tracebacks from the bottom up; use `try/except` sparingly.

### Environment

- Install Python via the official installer or a distribution like Anaconda/Miniconda.
- Use **virtual environments** (`python -m venv .venv`) and `pip install pandas` so each project has its own packages.
- Write code in VS Code or Jupyter.

### Mindset

In analysis you will mostly call libraries rather than write loops. If you find yourself looping over rows of a DataFrame, there is usually a vectorised pandas way.

**Pitfall:** trying to learn "all of Python" before touching data. Spend a week or two on the basics, then learn the rest through pandas work. Move on when you can write a small script that reads a CSV, filters rows with a function, and writes a summary file.

## Key concepts

- **Types, variables, f-strings**
- **Lists, dicts, sets, tuples**
- **Loops and comprehensions**
- **Functions**
- **Reading files and JSON**
- **Virtual environments and pip**
- **Reading tracebacks**
- **Calling APIs with requests**

## Other options for this step

- [R and the Tidyverse](https://www.internhack.in/roadmaps/tracks/data-analyst/r-for-analysis): An alternative analysis language with first-class statistics and the tidyverse for readable data pipelines.

## Mini project

Write a Python script that downloads a public CSV (e.g. a city's open data portal dataset), counts rows per category using only the standard library, and writes the result to a new CSV.

## Check yourself

When would you use a dict instead of a list, and how would you count occurrences of each category with one?

## Free resources

- [The Python Tutorial](https://docs.python.org/3/tutorial/) (Python.org)
- [Kaggle Python course](https://www.kaggle.com/learn/python) (Kaggle)
- [Data Analysis with Python](https://www.freecodecamp.org/learn/data-analysis-with-python/) (freeCodeCamp)

Previous: [Cloud Data Warehouses](https://www.internhack.in/roadmaps/tracks/data-analyst/cloud-warehouses) · Next: [R and the Tidyverse](https://www.internhack.in/roadmaps/tracks/data-analyst/r-for-analysis)

## More in Programming for Analysis

- [Python for Analysts](https://www.internhack.in/roadmaps/tracks/data-analyst/python-for-analysis)
- [R and the Tidyverse](https://www.internhack.in/roadmaps/tracks/data-analyst/r-for-analysis)
- [Jupyter Notebooks and Reproducible Work](https://www.internhack.in/roadmaps/tracks/data-analyst/jupyter-notebooks)
- [NumPy Essentials](https://www.internhack.in/roadmaps/tracks/data-analyst/numpy-basics)
- [pandas for Data Analysis](https://www.internhack.in/roadmaps/tracks/data-analyst/pandas-core)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Data Analyst Roadmap](https://www.internhack.in/roadmaps/tracks/data-analyst)
