String methods such as upper(), lower(), capitalize(), title(), and swapcase() help when we wish to convert all the string elements into an entire series. The upper and lower methods convert the entire string into uppercase or lowercase. The following command shows converting a series into uppercase:
sample_df["Movie"].str.upper()
The following is the output:
The following command shows converting a series into lowercase:
sample_df["Movie"].str.lower()
The following is the output:
The capitalize() method converts the first letter into uppercase and the rest into lowercase:
pd.Series(["elon musk", "tim cook", "larry page", "jeff bezos"]).str.capitalize()
The following is the output:
The title() method ensures that the first letter of each word of a string is capitalized while the rest are in lowercase:
pd.Series(["elon musk", "tim cook", "larry page", "jeff bezos"]).str.title()
The swapcase() method switches uppercase to lowercase and vice versa:
sample_df["Movie"].str.swapcase()
The following is the output: