I have the following csv
id;price;editor
k1;10,00;ed1
k1;8,00;ed2
k3;10,00;ed1
k3;11,00;ed2
k2;10,50;ed1
k1;9,50;ed3
If I do the following
Much like @Wen-Ben I choose to use sort_values
and drop_duplicates
, however, I converted the values using pd.read_csv
with the decimal
parameter.
from io import StringIO
csvfile = StringIO("""id;price;editor
k1;10,00;ed1
k1;8,00;ed2
k3;10,00;ed1
k3;11,00;ed2
k2;10,50;ed1
k1;9,50;ed3""")
df = pd.read_csv(csvfile, delimiter =';', decimal=',')
df.sort_values(['id','price']).drop_duplicates(['id'])
Output:
id price editor
1 k1 8.0 ed2
4 k2 10.5 ed1
2 k3 10.0 ed1