Become a data analyst in 90 days✦27 portfolio projects✦100+ interview Q&As✦1:1 mentor for a year✦See the 90-Day System →✦Become a data analyst in 90 days✦27 portfolio projects✦100+ interview Q&As✦1:1 mentor for a year✦See the 90-Day System →✦
New here? Want every day planned for you? See the 90-Day System →

Free PDF · Python

12 Python programs they love to ask

Plain Python first, then pandas. Type each one yourself before the interview.

DGPython12 Python programs they love to ask12 programs@thedataguy16

12 Python programs that keep showing up in analyst interviews.

First 8 are plain Python logic. Last 4 are pandas, the part that actually matters on the job.

Don't just read them. Type every line, run it, then explain it out loud like you're in the room.

Save this and code 2 a day.

Strings

Warm up. Everyone asks these.

  1. 01

    Reverse a string

    s = "analyst"
    print(s[::-1])  # tsylana
  2. 02

    Check a palindrome

    def is_pal(s):
        s = s.lower()
        return s == s[::-1]

Lists

The logic round starts.

  1. 03

    Top 3 most frequent words

    from collections import Counter
    words = text.split()
    print(Counter(words).most_common(3))
  2. 04

    Second largest number

    nums = [4, 9, 2, 9, 7]
    print(sorted(set(nums))[-2])  # 7

Lists

Where freshers freeze.

  1. 05

    Find duplicates in a list

    seen, dups = set(), set()
    for x in nums:
        if x in seen:
            dups.add(x)
        seen.add(x)
  2. 06

    Missing number from 1 to n

    n = len(nums) + 1
    missing = n * (n + 1) // 2 - sum(nums)

Logic

Clean code wins here.

  1. 07

    FizzBuzz, the classic filter

    for i in range(1, 16):
        if i % 15 == 0: print("FizzBuzz")
        elif i % 3 == 0: print("Fizz")
        elif i % 5 == 0: print("Buzz")
        else: print(i)
  2. 08

    Flatten a nested list

    grid = [[1, 2], [3, 4], [5]]
    flat = [x for row in grid for x in row]

pandas

Now the analyst part.

  1. 09

    Top 3 cities by revenue

    (df.groupby("city")["rev"].sum()
       .nlargest(3))
  2. 10

    Fill missing values with median

    med = df["age"].median()
    df["age"] = df["age"].fillna(med)

pandas

The ones that get you hired.

  1. 11

    Remove duplicate customers

    df = df.drop_duplicates(
        subset=["email"], keep="first")
  2. 12

    Month-wise sales

    df["m"] = df["date"].dt.to_period("M")
    df.groupby("m")["sales"].sum()

How to practise these

Don't

  • Memorise the code
  • Only read solutions
  • Skip edge cases

Do

  • Type every line
  • Explain it aloud
  • Test empty inputs

Free PDF

12 Python programs they love to ask

Download the PDF

Opens in Google Drive. No sign-up.

Keep going

More free PDFs

90-Day System · become a data analyst→