
- Python Pandas - Home
- Python Pandas - Introduction
- Python Pandas - Environment Setup
- Python Pandas - Basics
- Python Pandas - Introduction to Data Structures
- Python Pandas - Index Objects
- Python Pandas - Panel
- Python Pandas - Basic Functionality
- Python Pandas - Indexing & Selecting Data
- Python Pandas - Series
- Python Pandas - Series
- Python Pandas - Slicing a Series Object
- Python Pandas - Attributes of a Series Object
- Python Pandas - Arithmetic Operations on Series Object
- Python Pandas - Converting Series to Other Objects
- Python Pandas - DataFrame
- Python Pandas - DataFrame
- Python Pandas - Accessing DataFrame
- Python Pandas - Slicing a DataFrame Object
- Python Pandas - Modifying DataFrame
- Python Pandas - Removing Rows from a DataFrame
- Python Pandas - Arithmetic Operations on DataFrame
- Python Pandas - IO Tools
- Python Pandas - IO Tools
- Python Pandas - Working with CSV Format
- Python Pandas - Reading & Writing JSON Files
- Python Pandas - Reading Data from an Excel File
- Python Pandas - Writing Data to Excel Files
- Python Pandas - Working with HTML Data
- Python Pandas - Clipboard
- Python Pandas - Working with HDF5 Format
- Python Pandas - Comparison with SQL
- Python Pandas - Data Handling
- Python Pandas - Sorting
- Python Pandas - Reindexing
- Python Pandas - Iteration
- Python Pandas - Concatenation
- Python Pandas - Statistical Functions
- Python Pandas - Descriptive Statistics
- Python Pandas - Working with Text Data
- Python Pandas - Function Application
- Python Pandas - Options & Customization
- Python Pandas - Window Functions
- Python Pandas - Aggregations
- Python Pandas - Merging/Joining
- Python Pandas - MultiIndex
- Python Pandas - Basics of MultiIndex
- Python Pandas - Indexing with MultiIndex
- Python Pandas - Advanced Reindexing with MultiIndex
- Python Pandas - Renaming MultiIndex Labels
- Python Pandas - Sorting a MultiIndex
- Python Pandas - Binary Operations
- Python Pandas - Binary Comparison Operations
- Python Pandas - Boolean Indexing
- Python Pandas - Boolean Masking
- Python Pandas - Data Reshaping & Pivoting
- Python Pandas - Pivoting
- Python Pandas - Stacking & Unstacking
- Python Pandas - Melting
- Python Pandas - Computing Dummy Variables
- Python Pandas - Categorical Data
- Python Pandas - Categorical Data
- Python Pandas - Ordering & Sorting Categorical Data
- Python Pandas - Comparing Categorical Data
- Python Pandas - Handling Missing Data
- Python Pandas - Missing Data
- Python Pandas - Filling Missing Data
- Python Pandas - Interpolation of Missing Values
- Python Pandas - Dropping Missing Data
- Python Pandas - Calculations with Missing Data
- Python Pandas - Handling Duplicates
- Python Pandas - Duplicated Data
- Python Pandas - Counting & Retrieving Unique Elements
- Python Pandas - Duplicated Labels
- Python Pandas - Grouping & Aggregation
- Python Pandas - GroupBy
- Python Pandas - Time-series Data
- Python Pandas - Date Functionality
- Python Pandas - Timedelta
- Python Pandas - Sparse Data Structures
- Python Pandas - Sparse Data
- Python Pandas - Visualization
- Python Pandas - Visualization
- Python Pandas - Additional Concepts
- Python Pandas - Caveats & Gotchas
Pandas Series.str.lower() Method
The Series.str.lower() method in in Python Pandas library is used to convert strings in a Series or Index to lowercase. This method is useful for text normalization and data preprocessing, as it ensures consistency in text data by converting all characters to lowercase.
Using this method can help in performing case-insensitive comparisons and analyses more effectively. And this is equivalent to Python's built-in str.lower() method and is commonly used in data cleaning and preprocessing tasks.
Syntax
Following is the syntax of the Pandas Series.str.lower() method −
Series.str.lower()
Parameters
The Pandas Series.str.lower() method does not accept any parameters.
Return Value
The Series.str.lower() method returns a Series or Index of the same shape, where each string has been converted to lowercase. This means that all characters in each string are converted to their lowercase form.
Example 1
Let's look at a basic example to understand how the Series.str.lower() method works −
import pandas as pd # Create a Series s = pd.Series(['Hello', 'WORLD', 'Pandas']) # Display the input Series print("Input Series") print(s) # Apply the lower method print("Series after applying the lower:") print(s.str.lower())
When we run the above program, it produces the following result −
Input Series 0 Hello 1 WORLD 2 Pandas dtype: object Series after applying the lower: 0 hello 1 world 2 pandas dtype: object
Example 2
In this example, we'll demonstrate the use of the Series.str.lower() method in a DataFrame −
import pandas as pd # Create a DataFrame df = pd.DataFrame({'Name': ['Alice', 'Bob', 'CHARLIE'], 'Role': ['ADMIN', 'User', 'Manager']}) # Print the original DataFrame print("Input DataFrame") print(df) # Apply the lower method to the 'Role' column df['Role'] = df['Role'].str.lower() # Print the modified DataFrame print("Modified DataFrame:") print(df)
Following is the output of the above code −
Input DataFrame Name Role 0 Alice ADMIN 1 Bob User 2 CHARLIE Manager Modified DataFrame Name Role 0 Alice admin 1 Bob user 2 CHARLIE manager
Example 3
Let's see another example where we apply Series.str.lower() method to an Index object of the pandas DataFrame.
import pandas as pd # Create a DataFrame with an Index df = pd.DataFrame({'Value': [1, 2, 3]}, index=['First', 'SECOND', 'THIRD']) # Print the original DataFrame print("Original DataFrame:") print(df) # Apply lower to the DataFrame index labels df.index = df.index.str.lower() # Print the modified DataFrame print("Modified DataFrame:") print(df)
Output of the above code is as follows −
Original DataFrame: Value First 1 SECOND 2 THIRD 3 Modified DataFrame: Value first 1 second 2 third 3