w3resource

Pandas Series: str.capitalize() function

Series-str.capitalize() function

The str.capitalize() function is used to convert strings in the Series/Index to be capitalized.

The method is equivalent to str.capitalize().

Series.str.capitalize(self)
Pandas Series: str.capitalize() function

Returns: Series/Index of objects

Example:

Python-Pandas Code:

import numpy as np
import pandas as pd
s = pd.Series(['long', 'CAPTAIN', 'this is my car', 'FoOtBaLl'])
s

Output:

0              long
1           CAPTAIN
2    this is my car
3          FoOtBaLl
dtype: object
Pandas Series: str.capitalize() function

Python-Pandas Code:

import numpy as np
import pandas as pd
s = pd.Series(['long', 'CAPTAIN', 'this is my car', 'FoOtBaLl'])
s.str.capitalize()

Output:

0              Long
1           Captain
2    This is my car
3          Football
dtype: object

Previous: Series-dt.total_seconds() function
Next: Series-str.casefold() function



Follow us on Facebook and Twitter for latest update.