NumPy strings.title()
The numpy.strings.title() function returns the title-cased version of each string in an array.
Title case means that each word starts with an uppercase letter, and all other characters are converted to lowercase.
Syntax
</>
Copy
numpy.strings.title(a)
Parameters
| Parameter | Type | Description |
|---|---|---|
a | array-like, with StringDType, bytes_, or str_ dtype | Input array containing strings that need to be title-cased. |
Return Value
Returns an ndarray containing the title-cased version of each string in the input array.
Examples
1. Title-Casing a Single Word
In this example, we will take a single word in lowercase, and convert this lowercase word to title case.
</>
Copy
import numpy as np
# Define a single word in an array
word = np.array(['apple'], dtype='U')
# Apply title-casing
result = np.strings.title(word)
# Print the result
print("Title-cased word:", result)
Output:
Title-cased word: ['Apple']
