
- Python Pandas 教程
- Python Pandas - 首頁
- Python Pandas - 簡介
- Python Pandas - 環境搭建
- Python Pandas - 基礎
- Python Pandas - 資料結構簡介
- Python Pandas - 索引物件
- Python Pandas - Panel
- Python Pandas - 基本功能
- Python Pandas - 索引和資料選擇
- Python Pandas - Series
- Python Pandas - Series
- Python Pandas - Series 物件切片
- Python Pandas - Series 物件的屬性
- Python Pandas - Series 物件的算術運算
- Python Pandas - 將 Series 轉換為其他物件
- Python Pandas - DataFrame
- Python Pandas - DataFrame
- Python Pandas - 訪問 DataFrame
- Python Pandas - DataFrame 物件切片
- Python Pandas - 修改 DataFrame
- Python Pandas - 從 DataFrame 中刪除行
- Python Pandas - DataFrame 的算術運算
- Python Pandas - I/O 工具
- Python Pandas - I/O 工具
- Python Pandas - 使用 CSV 格式
- Python Pandas - 讀取和寫入 JSON 檔案
- Python Pandas - 從 Excel 檔案讀取資料
- Python Pandas - 將資料寫入 Excel 檔案
- Python Pandas - 使用 HTML 資料
- Python Pandas - 剪貼簿
- Python Pandas - 使用 HDF5 格式
- Python Pandas - 與 SQL 的比較
- Python Pandas - 資料處理
- Python Pandas - 排序
- Python Pandas - 重新索引
- Python Pandas - 迭代
- Python Pandas - 級聯
- Python Pandas - 統計函式
- Python Pandas - 描述性統計
- Python Pandas - 使用文字資料
- Python Pandas - 函式應用
- Python Pandas - 選項和自定義
- Python Pandas - 視窗函式
- Python Pandas - 聚合
- Python Pandas - 合併/連線
- Python Pandas - 多索引
- Python Pandas - 多索引基礎
- Python Pandas - 使用多索引進行索引
- Python Pandas - 使用多索引進行高階重新索引
- Python Pandas - 重新命名多索引標籤
- Python Pandas - 對多索引進行排序
- Python Pandas - 二元運算
- Python Pandas - 二元比較運算
- Python Pandas - 布林索引
- Python Pandas - 布林掩碼
- Python Pandas - 資料重塑和透視
- Python Pandas - 透視
- Python Pandas - 堆疊和取消堆疊
- Python Pandas - 熔化
- Python Pandas - 計算虛擬變數
- Python Pandas - 分類資料
- Python Pandas - 分類資料
- Python Pandas - 分類資料的排序和分類
- Python Pandas - 分類資料的比較
- Python Pandas - 處理缺失資料
- Python Pandas - 缺失資料
- Python Pandas - 填充缺失資料
- Python Pandas - 缺失值的插值
- Python Pandas - 刪除缺失資料
- Python Pandas - 使用缺失資料進行計算
- Python Pandas - 處理重複項
- Python Pandas - 重複資料
- Python Pandas - 計數和檢索唯一元素
- Python Pandas - 重複標籤
- Python Pandas - 分組和聚合
- Python Pandas - GroupBy
- Python Pandas - 時間序列資料
- Python Pandas - 日期功能
- Python Pandas - Timedelta
- Python Pandas - 稀疏資料結構
- Python Pandas - 稀疏資料
- Python Pandas - 視覺化
- Python Pandas - 視覺化
- Python Pandas - 其他概念
- Python Pandas - 警告和陷阱
- Python Pandas 有用資源
- Python Pandas - 快速指南
- Python Pandas - 有用資源
- Python Pandas - 討論
Pandas Series.str.lower() 方法
Python Pandas 庫中的Series.str.lower()方法用於將 Series 或 Index 中的字串轉換為小寫。此方法對於文字規範化和資料預處理非常有用,因為它透過將所有字元轉換為小寫來確保文字資料的一致性。
使用此方法可以更有效地執行不區分大小寫的比較和分析。這等效於 Python 的內建str.lower()方法,通常用於資料清洗和預處理任務。
語法
以下是 Pandas Series.str.lower() 方法的語法:
Series.str.lower()
引數
Pandas Series.str.lower()方法不接受任何引數。
返回值
Series.str.lower()方法返回一個形狀相同的 Series 或 Index,其中每個字串都已轉換為小寫。這意味著每個字串中的所有字元都轉換為其小寫形式。
示例 1
讓我們來看一個基本的例子,瞭解 Series.str.lower() 方法是如何工作的:
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())
執行上述程式後,會產生以下結果:
Input Series 0 Hello 1 WORLD 2 Pandas dtype: object Series after applying the lower: 0 hello 1 world 2 pandas dtype: object
示例 2
在這個例子中,我們將演示在 DataFrame 中使用 Series.str.lower() 方法。
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)
以上程式碼的輸出如下:
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
示例 3
讓我們來看另一個例子,我們將 Series.str.lower() 方法應用於 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)
以上程式碼的輸出如下:
Original DataFrame: Value First 1 SECOND 2 THIRD 3 Modified DataFrame: Value first 1 second 2 third 3
python_pandas_working_with_text_data.htm
廣告