A common trap: spending months on "complete Python" courses that cover classes, decorators, threads and web frameworks before you ever open a dataset. For data analysis, you need a focused slice of Python. This article lists that slice.
Strings
Data is full of text: names, cities, product codes, messy categories. Learn:
- Indexing and slicing:
code[:3]for the first three characters. - Methods:
strip(),lower(),upper(),replace(),split(),startswith(). - f-strings for readable output:
f"{city}: {orders} orders".
raw = " Navi Mumbai "
clean = raw.strip().title() # "Navi Mumbai"Everything you learn here carries straight into pandas, where df["city"].str.strip() does the same thing for a whole column.
Lists
A list is an ordered collection. Learn to index, slice, append, sort and loop over lists, and know the difference between sorted(x) (returns a new list) and x.sort() (changes x in place, returns None).
Dictionaries
Dictionaries map keys to values, and they are everywhere in data work: a row of data is basically a dictionary, JSON from an API is nested dictionaries, and counting things is a dictionary job.
counts = {}
for city in ["Pune", "Delhi", "Pune", "Jaipur", "Pune"]:
counts[city] = counts.get(city, 0) + 1
# {'Pune': 3, 'Delhi': 1, 'Jaipur': 1}If you can write this counting loop from memory, you understand dictionaries well enough to start.
Tuples and sets
Know that tuples are like lists that cannot change, and sets hold unique values. Sets are handy for questions like "which customers ordered in January but not in February?" using set difference.
Loops and conditions
for loops with if / elif / else, plus enumerate and zip. You will loop less once you learn pandas (pandas works on whole columns at once), but you need loops to understand what pandas is doing for you.
Functions
Write small functions with parameters, default values and return values. Functions make your analysis reusable: the cleaning you did for January's file should be one function call for February's.
def late_share(delivery_times, limit=40):
late = [t for t in delivery_times if t > limit]
return len(late) / len(delivery_times)Lambda, map, filter, sorted
Short anonymous functions appear often in pandas code (df["x"].apply(lambda v: ...)) and in sorting by a key (sorted(rows, key=lambda r: r["amount"])). Understand them; do not overuse them.
Comprehensions
List and dictionary comprehensions are compact loops. They are very common in real code, so you must be able to read them:
squares = [n * n for n in range(10) if n % 2 == 0]
price_with_gst = {item: round(p * 1.18, 2) for item, p in prices.items()}What you can skip for now
- Classes and object-oriented design (you will use objects, like DataFrames, but rarely write classes as an analyst).
- Decorators, generators in depth, async code.
- Web frameworks like Django or Flask.
- Memorising every built-in function.
How to check you are ready for pandas
Try ten mixed questions without help. If you can solve most of them, start pandas. Our Python practice test 1 is designed for exactly this check. Then go straight to the pandas operations analysts use every day.
Practise what you just read
Reading helps; writing the code yourself is what sticks. Start here: