pandas.Series.str.swapcase

Convert strings in the Series/Index to be swapcased.

Equivalent to str.swapcase().

return

Series/Index of objects

Limitations

  • All values in Series equal to None are converted to NaNs.

  • This function may reveal slower performance than Pandas* on user system. Users should exercise a tradeoff

    between staying in JIT-region with that function or going back to interpreter mode.

Examples

Convert strings in the Series to be swapcased.
import pandas as pd
from numba import njit


@njit
def series_str_swapcase():
    series = pd.Series(['lower', 'CAPITALS', 'this is a sentence', 'SwApCaSe'])
    out_series = series.str.swapcase()

    return out_series  # Expect series of 'LOWER', 'capitals', 'THIS IS A SENTENCE', 'sWaPcAsE'


print(series_str_swapcase())
$ python ./series/str/series_str_swapcase.py
0                 LOWER
1              capitals
2    THIS IS A SENTENCE
3              sWaPcAsE
dtype: object

See also

Series.str.lower

Converts all characters to lowercase.

Series.str.upper

Converts all characters to uppercase.

Series.str.title

Converts first character of each word to uppercase and remaining to lowercase.

Series.str.capitalize

Converts first character to uppercase and remaining to lowercase.

Series.str.swapcase

Converts uppercase to lowercase and lowercase to uppercase.

Series.str.casefold

Removes all case distinctions in the string.