w3resource

Pandas Series: str.swapcase() function

Series-str.swapcase() function

The str.swapcase() function is used to convert strings in the Series/Index to be swapcased.
The function is equivalent to str.swapcase().

Syntax:

Series.str.title(self)
Pandas Series: str.swapcase() 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 a car', 'FoOtBaLl'])
s

Output:

0             long
1          CAPTAIN
2    this is a car
3         FoOtBaLl
dtype: object

Python-Pandas Code:

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

Output:

0             LONG
1          captain
2    THIS IS A CAR
3         fOoTbAlL
dtype: object

Previous: Series-str.strip() function
Next: Series-str.title() 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-swapcase.php