python pandas series to title case 1

python pandas series to title case

>>> s = pd.Series(['lower', 'CAPITALS', 'this is a sentence', 'SwApCaSe'])
>>> s.str.title()
0                 Lower
1              Capitals
2    This Is A Sentence
3              Swapcase
dtype: object

Here is what the above code is Doing:
1. We create a Series object with four strings.
2. We call the str attribute of the Series object and then call the title method.
3. The title method returns a new Series object with the same index as the original Series object.

Similar Posts