0
0
Pandasdata~5 mins

str.lower() and str.upper() in Pandas - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the str.lower() method do in pandas?
It converts all characters in a string column of a pandas DataFrame or Series to lowercase letters.
Click to reveal answer
beginner
How does str.upper() affect text data in pandas?
It changes all characters in a string column to uppercase letters, making the text all capitalized.
Click to reveal answer
beginner
Example: What will df['Name'].str.lower() do if df['Name'] contains ['Alice', 'BOB', 'Charlie']?
It will return a Series with ['alice', 'bob', 'charlie'], converting all names to lowercase.
Click to reveal answer
intermediate
Can str.lower() and str.upper() be used on non-string columns in pandas?
No, these methods only work on string columns. Non-string columns must be converted to strings first.
Click to reveal answer
beginner
Why might you want to use str.lower() or str.upper() in data cleaning?
To standardize text data so that comparisons and searches are case-insensitive and consistent.
Click to reveal answer
What does df['City'].str.upper() do in pandas?
AConverts all city names to lowercase letters
BConverts all city names to uppercase letters
CRemoves spaces from city names
DSplits city names into separate words
If you want to make text comparisons case-insensitive, which method helps?
Astr.lower()
Bstr.split()
Cstr.strip()
Dstr.replace()
What happens if you use str.upper() on a numeric column without converting it first?
AIt raises an error because numbers are not strings
BIt removes the numeric column
CIt converts numbers to strings automatically
DIt works and converts numbers to uppercase
Which pandas attribute allows you to apply string methods like lower() and upper()?
Adt
Bapply
Ccat
Dstr
What is the output of pd.Series(['Hi', 'Bye']).str.lower()?
A['Hi', 'Bye']
B['HI', 'BYE']
C['hi', 'bye']
DError
Explain how and why you would use str.lower() and str.upper() in cleaning text data in pandas.
Think about making text uniform to avoid mismatches.
You got /4 concepts.
    Describe what happens if you try to use str.upper() on a numeric column in pandas and how to fix it.
    Consider data types and method compatibility.
    You got /4 concepts.