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



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/pandas/series/series-str-capitalize.php