このページの翻訳:
- 日本語 (ja)
- English (en)
最近の更新
最近の更新
import pandas as pd
# データフレームの生成
df = pd.DataFrame({'A': ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'bar'],
'B': ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'],
'C': [1, 2, 3, 4, 3, 2, 1, 4]})
print("Original DataFrame:")
print(df)
# 重複行の削除
df_no_duplicates = df.drop_duplicates()
print("\nDataFrame after removing duplicates:")
print(df_no_duplicates)
この場合結果はこうなる
Original DataFrame: A B C 0 foo one 1 1 bar one 2 2 foo two 3 3 bar three 4 4 foo two 3 5 bar two 2 6 foo one 1 7 bar three 4 DataFrame after removing duplicates: A B C 0 foo one 1 1 bar one 2 2 foo two 3 3 bar three 4 5 bar two 2
df_no_duplicates_A = df.drop_duplicates(subset=['A']) print("\nDataFrame after removing duplicates in column 'A':") print(df_no_duplicates_A)
この場合結果はこうなる
Original DataFrame: A B C 0 foo one 1 1 bar one 2 2 foo two 3 3 bar three 4 4 foo two 3 5 bar two 2 6 foo one 1 7 bar three 4 DataFrame after removing duplicates in column 'A': A B C 0 foo one 1 1 bar one 2