You can use the keep parameter in the drop_duplicates() method to specify whether to keep the first occurrence or the last occurrence of duplicate rows. To keep the last occurrence, set keep='last'.
Here's an example:
import pandas as pd
# Sample DataFrame
data = {'A': [1, 2, 2, 3, 4],
'B': ['X', 'Y', 'Y', 'Z', 'X']}
df = pd.DataFrame(data)
# Keep the last occurrence of duplicate rows based on column 'A'
df_no_duplicates = df.drop_duplicates(subset=['A'], keep='last')
print(df_no_duplicates)