MCPcopy
hub / github.com/pandas-dev/pandas / swapcase

Method swapcase

pandas/core/strings/accessor.py:4138–4207  ·  view source on GitHub ↗

Convert strings in the Series/Index to be swapcased. Equivalent to :meth:`str.swapcase`. Returns ------- Series or Index of objects A Series or Index where the strings are modified by :meth:`str.swapcase`. See Also --------

(self)

Source from the content-addressed store, hash-verified

4136
4137 @forbid_nonstring_types(["bytes"])
4138 def swapcase(self):
4139 """
4140 Convert strings in the Series/Index to be swapcased.
4141
4142 Equivalent to :meth:`str.swapcase`.
4143
4144 Returns
4145 -------
4146 Series or Index of objects
4147 A Series or Index where the strings are modified by :meth:`str.swapcase`.
4148
4149 See Also
4150 --------
4151 Series.str.lower : Converts all characters to lowercase.
4152 Series.str.upper : Converts all characters to uppercase.
4153 Series.str.title : Converts first character of each word to uppercase and
4154 remaining to lowercase.
4155 Series.str.capitalize : Converts first character to uppercase and
4156 remaining to lowercase.
4157 Series.str.swapcase : Converts uppercase to lowercase and lowercase to
4158 uppercase.
4159 Series.str.casefold: Removes all case distinctions in the string.
4160
4161 Examples
4162 --------
4163 >>> s = pd.Series(["lower", "CAPITALS", "this is a sentence", "SwApCaSe"])
4164 >>> s
4165 0 lower
4166 1 CAPITALS
4167 2 this is a sentence
4168 3 SwApCaSe
4169 dtype: str
4170
4171 >>> s.str.lower()
4172 0 lower
4173 1 capitals
4174 2 this is a sentence
4175 3 swapcase
4176 dtype: str
4177
4178 >>> s.str.upper()
4179 0 LOWER
4180 1 CAPITALS
4181 2 THIS IS A SENTENCE
4182 3 SWAPCASE
4183 dtype: str
4184
4185 >>> s.str.title()
4186 0 Lower
4187 1 Capitals
4188 2 This Is A Sentence
4189 3 Swapcase
4190 dtype: str
4191
4192 >>> s.str.capitalize()
4193 0 Lower
4194 1 Capitals
4195 2 This is a sentence

Callers 8

test_swapcaseFunction · 0.80
test_casemethodsFunction · 0.80
test_replace_callableFunction · 0.80
test_empty_str_methodsFunction · 0.80

Calls 2

_wrap_resultMethod · 0.95
_str_swapcaseMethod · 0.45

Tested by 8

test_swapcaseFunction · 0.64
test_casemethodsFunction · 0.64
test_replace_callableFunction · 0.64
test_empty_str_methodsFunction · 0.64