====== 2023.08.31 Pandas指定行削除 ====== Pandasで指定行を削除したい場合がある。 その場合dropを利用する。 import pandas as pd # Create a sample DataFrame df = pd.DataFrame({ 'A': [1, 2, 3, 4, 5], 'B': [10, 20, 30, 40, 50], 'C': [100, 200, 300, 400, 500] }) print(df) 結果 A B C 0 1 10 100 1 2 20 200 2 3 30 300 3 4 40 400 4 5 50 500 ===== 指定行削除 ===== df = df.drop(2) print(df) 結果 A B C 0 1 10 100 1 2 20 200 3 4 40 400 4 5 50 500 ===== 指定行複数削除 ===== df = df.drop([1, 3]) print(df) A B C 0 1 10 100 4 5 50 500 {{tag>日記 python pandas}}