← 30 Days of Python
Day 2 / 30Strings

Strings — Manipulation & Methods

Data analysts deal with messy text every day — customer names, product codes, city names with inconsistent casing. String methods are not optional.

1
Easy

How do you convert a string to uppercase and lowercase?

Python Answer
s = "Hello World"
s.upper()   # "HELLO WORLD"
s.lower()   # "hello world"
s.title()   # "Hello World"
💡

In data cleaning, .lower() is used to standardise column values before grouping — e.g. "Mumbai" and "MUMBAI" should count as the same city.

2
Easy

How do you remove whitespace from a string?

Python Answer
s = "  hello  "
s.strip()    # "hello"  — both sides
s.lstrip()   # "hello  "  — left only
s.rstrip()   # "  hello"  — right only
💡

Leading/trailing spaces are one of the most common data quality issues in CSV files. Always .strip() string columns after import.

3
Medium

How do you split a string into a list?

Python Answer
s = "Delhi,Mumbai,Noida"
parts = s.split(",")   # ["Delhi", "Mumbai", "Noida"]

# Rejoin:
",".join(parts)         # "Delhi,Mumbai,Noida"
💡

split() is used to parse delimited fields — comma-separated tags, pipe-separated codes. join() is the reverse and is faster than string concatenation in loops.

4
Easy

How do you check if a string contains a substring?

Python Answer
s = "data analyst noida"
"noida" in s         # True
s.find("noida")      # 14 (index) or -1 if not found
s.startswith("data") # True
s.endswith("ida")    # True
💡

The in operator is the Pythonic way. In Pandas, use df["city"].str.contains("Noida", case=False) to filter rows with partial text matches.

5
Easy

How do you replace part of a string?

Python Answer
s = "data_analyst_noida"
s.replace("_", " ")   # "data analyst noida"

# Pandas column:
df["name"] = df["name"].str.replace("Ltd.", "Limited")
💡

.replace() on a string replaces all occurrences. In Pandas, .str.replace() supports regex — powerful for cleaning phone numbers, product codes, etc.

6
Medium

How do you count occurrences of a character in a string?

Python Answer
s = "banana"
s.count("a")   # 3
len(s)         # 6
💡

.count() is useful in text analysis. len() gives total length — you can use it to filter out entries that are too short (likely invalid) or too long (possibly dirty data).

EVIKA ACADEMY · PYTHON FOR DATA ANALYTICS

Want to master Python with live practice?

Join our Python for Data Analysis course — live classes in Noida and online across India.

Book Free Demo Class →
← PREVIOUSDay 1: Python Basics — Variables, Data Types & PrintNEXT →Day 3: Lists — Operations & Methods
Best Data Analytics Course in Noida Delhi NCR | EVIKA ACADEMY