Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ def g(x):
else:
return lib.map_infer(arr, f)

def str_title(arr):
"""
Convert strings to titlecased version

Returns
-------
titled : array
"""
return _na_map(lambda x: x.title(), arr)


def str_count(arr, pat, flags=0):
"""
Expand Down Expand Up @@ -744,3 +754,4 @@ def rstrip(self, to_strip=None):
len = _noarg_wrapper(str_len)
lower = _noarg_wrapper(str_lower)
upper = _noarg_wrapper(str_upper)
title = _noarg_wrapper(str_title)
22 changes: 22 additions & 0 deletions pandas/tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@ def test_endswith(self):
result = values.str.endswith('foo', na=False)
tm.assert_series_equal(result, exp.fillna(False).astype(bool))

def test_title(self):
values = Series(["FOO", "BAR", NA, "Blah", "blurg"])

result = values.str.title()
exp = Series(["Foo", "Bar", NA, "Blah", "Blurg"])
tm.assert_series_equal(result, exp)

# mixed
mixed = Series(["FOO", NA, "bar", True, datetime.today(),
"blah", None, 1, 2.])
mixed = mixed.str.title()
exp = Series(["Foo", NA, "Bar", NA, NA, "Blah", NA, NA, NA])
tm.assert_almost_equal(mixed, exp)

# unicode
values = Series([u"FOO", NA, u"bar", u"Blurg"])

results = values.str.title()
exp = Series([u"Foo", NA, u"Bar", u"Blurg"])

tm.assert_series_equal(results, exp)

def test_lower_upper(self):
values = Series(['om', NA, 'nom', 'nom'])

Expand Down