Lowercase a String Series in pandas

Quick Overview

Write a pandas function that returns a lowercased copy of a string Series while keeping NaN values, the original index and the name intact. It tests vectorized string methods, how missing values flow through them, and writing cleaning code that never mutates its input.

Lowercase a String Series in pandas

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Implement `def to_lower(s: pd.Series) -> pd.Series` that returns a new Series with every string value lowercased using `s.str.lower()`. Requirements: - Do not mutate the input. - Leave `NaN` values as `NaN`. - Preserve the original `index` and `name`. Example: ```python to_lower(pd.Series(['ALICE', 'Bob', 'cAROL'])) # returns pd.Series(['alice', 'bob', 'carol']) ``` ```hint What the accessor gives back Check whether `s.str.lower()` changes `s` in place or builds a new object, and what it does with entries that are not strings. ``` ### What a Strong Answer Covers - Which pandas method does the work, and why a vectorized method fits this task - Whether the input is modified, and whether an explicit copy is needed - How missing values pass through, and what a per-element Python call would do with them - How the result keeps the original index and name - What happens with non-string values or a non-text dtype ### Follow-up Questions - The Series holds strings, integers and missing values together. What does `s.str.lower()` return for each, and how would you keep the integers unchanged? - When would you use `str.casefold()` instead of `str.lower()`? - What changes if the Series uses the `string` dtype instead of `object`? - How would you lowercase every text column of a DataFrame without modifying the original DataFrame?

Overview: Write a pandas function that returns a lowercased copy of a string Series while keeping NaN values, the original index and the name intact. It tests vectorized string methods, how missing values flow through them, and writing cleaning code that never mutates its input.

PracHub logo
General
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

Implement def to_lower(s: pd.Series) -> pd.Series that returns a new Series with every string value lowercased using s.str.lower().

Requirements:

  • Do not mutate the input.
  • Leave NaN values as NaN .
  • Preserve the original index and name .

Example:

to_lower(pd.Series(['ALICE', 'Bob', 'cAROL']))
# returns pd.Series(['alice', 'bob', 'carol'])

What a Strong Answer Covers Guidance

  • Which pandas method does the work, and why a vectorized method fits this task
  • Whether the input is modified, and whether an explicit copy is needed
  • How missing values pass through, and what a per-element Python call would do with them
  • How the result keeps the original index and name
  • What happens with non-string values or a non-text dtype

Follow-up Questions Guidance

  • The Series holds strings, integers and missing values together. What does s.str.lower() return for each, and how would you keep the integers unchanged?
  • When would you use str.casefold() instead of str.lower() ?
  • What changes if the Series uses the string dtype instead of object ?
  • How would you lowercase every text column of a DataFrame without modifying the original DataFrame?