I have a large dataframe which is in long format and can be created below:
import pandas as pd
df = pd.DataFrame({'period':['2021-01-01','2021-02-01','2021-03-01','2021-03-01','2021-04-01','2021-04-01'],
'indi':['pop','vacced','tot_num_cases','tot_num_cases','pop','pop'],
'value':[10000,200,8999,8999,27000,27000]})
I want to drop duplicate rows based on the condition below:
df[df['indi'] == 'tot_num_cases'].drop_duplicates(keep="last")
but only on the rows which match the condition. How do that without dropping all duplicate rows of the dataframe. Result would look like:
