0

Suppose I have a pandas dataframe like this:

  id val
0 1 1.0 
1 1 2.0 
2 2 1.5 
3 2 1.3 
4 3 1.4 
5 3 1.0 
6 3 2.1 
7 1 0.8 
8 2 1.2 
9 3 1.0 

In this example, I would like to get the rows with the minimum 'val' for each id. So I would like to get something like this:

  id val
0 1 0.8 
1 2 1.2 
2 3 1.0

How can I do that? In this case, the condition to select a row is dependent on a subset of the dataframe (minimum val for the subset with certain id).

So the more general question is: how to select rows based on conditions that are dependent on subsets of the dataframe?

peterdb
  • 1
  • 1
  • Can you explain more `how to select rows based on conditions that are dependent on subsets of the dataframe` ? – jezrael Jan 25 '18 at 11:23
  • jezrael, thanks for pointing me to the duplicate! That was what I was looking for. – peterdb Jan 25 '18 at 11:40

0 Answers0