Pandas Series Str Lower
[ Pandas Common Functions](#)
* * *
`Series.str.lower()` is a function in Pandas used to convert strings to lowercase.
In data processing, we often need to unify the case format of strings, such as converting user input names, addresses, etc., to lowercase for unified comparison and lookup. The `lower()` function can convert all strings in a Series to lowercase form.
**Word Meaning**: `lower` means "reduce, make smaller", here it refers to converting letters to lowercase.
* * *
## Basic Syntax and Parameters
`str.lower()` is a string accessor method of Series, so you first need a Series containing strings, then call it through the `.str` accessor.
### Syntax Format
Series.str.lower()
### Parameter Description
* **Parameter**: No parameters. This function does not require any parameters and can be called directly.
### Function Description
* **Return Value**: Returns a Series containing lowercase strings, with the same length as the original Series.
* **Effect**: Converts each string element in the Series to lowercase form, non-string elements remain unchanged.
* **Note**: This function only converts alphabetic characters, numbers, punctuation marks, and other characters remain unchanged.
* * *
## Examples
Let's master the usage of `str.lower()` through a series of examples from simple to complex.
### Example 1: Basic Usage - Converting Simple Strings
## Example
import pandas as pd
# Create a Series containing uppercase strings
s = pd.Series(['HELLO','WORLD','TUTORIAL','PYTHON'])
# Use str.lower() to convert all strings to lowercase
result = s.str.lower()
print("Original Series:")
print(s)
print("nConverted result:")
print(result)
**Output Result:**
Original Series:0 HELLO 1 WORLD 2 TUTORIAL 3 PYTHON dtype: objectConverted result:0 hello 1 world 2 tutorial 3 python dtype: object
**Code Explanation:**
1. `pd.Series(['HELLO', 'WORLD', 'TUTORIAL', 'PYTHON'])` creates a Series containing uppercase strings.
2. `s.str.lower()` calls the `lower()` method via the string accessor `.str`, converting all strings to lowercase.
3. The converted result is a new Series, leaving the original Series unchanged.
### Example 2: Conversion of Mixed Case Strings
When strings contain mixed uppercase and lowercase characters, `lower()` will convert all uppercase letters to lowercase.
## Example
import pandas as pd
# Create a Series containing mixed case strings
s = pd.Series(['Hello World','Online Tutorial','PyThOn','Pandas'])
# Use str.lower() to convert to lowercase
result = s.str.lower()
print("Original Series:")
print(s)
print("nConverted result:")
print(result)
**Output Result:**
Original Series:0 Hello World1 Online Tutorial2 PyThOn3 Pandas dtype: objectConverted result:0 hello world 1 tutorial tutorial 2 python 3 pandas dtype: object
**Code Explanation:**
* Regardless of how many uppercase letters are in the string, `lower()` will convert them all to lowercase.
* Spaces, numbers, and punctuation marks remain unchanged.
* This is very useful in data cleaning, such as standardizing user input name formats.
### Example 3: Case-Insensitive Comparison
`lower()` is often used to implement case-insensitive string comparisons.
## Example
import pandas as pd
# Create a product name Series
products = pd.Series(['Apple','BANANA','Orange','Grape'])
# User input search keyword (could be any case)
search_keyword ='BANANA'
# Convert both sides to lowercase for case-insensitive comparison
matches = products.str.lower()== search_keyword.lower()
print("Product List:")
print(products)
print(f"nSearch Keyword: {search_keyword}")
print("Match Results:")
print(products)
**Output Result:**
Product List:0 Apple1 BANANA 2 Orange3 Grape dtype: objectSearch Keyword: BANANA Match Results:1 BANANA dtype: object
**Code Explanation:**
* `products.str.lower()` converts product names to lowercase.
* `search_keyword.lower()` also converts the search keyword to lowercase.
* By comparing two lowercase strings, a case-insensitive match is achieved.
* * *
## Notes
* `str.lower()` only converts alphabetic characters; numbers, spaces, punctuation marks, and other non-alphabetic characters remain unchanged.
* If the Series contains non-string elements (such as NaN, integers), `lower()` leaves them unchanged without throwing an error.
* This function returns a new Series and does not modify the original data.
* For Chinese strings, Chinese characters are unaffected since Chinese has no concept of case.
* * Pandas Common Functions](#)
YouTip