User Tools

Site Tools


pandas_groupby

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
pandas_groupby [2021/07/06 23:02] – [preserve the highest odd value in each group] adminpandas_groupby [2021/07/06 23:09] – [preserve the highest odd value in each group] admin
Line 77: Line 77:
  
 ==== preserve the highest odd value in each group ==== ==== preserve the highest odd value in each group ====
 +tags | pandas groupby transform maximum odd number, maxodd
 Given Given
 <code> <code>
Line 93: Line 94:
 11  MM7  S7          3 11  MM7  S7          3
 </code> </code>
-get all the rows with highest odd 'count' for each ['Sp', 'Mt'] combination. That is, we want+ 
 +We want
 <code> <code>
      Sp  Mt Value  count      Sp  Mt Value  count
Line 103: Line 105:
 11  MM7  S7          3 11  MM7  S7          3
 </code> </code>
 +That is get all the rows with highest odd 'count' for each ['Sp', 'Mt'] combination.
 +If there is a group with only even 'count' values, discard it.
 +
 Solution Solution
 <code> <code>
Line 169: Line 174:
  
 In [5]: In [5]:
-df.groupby(['Sp', 'Mt'])['count'].transform(max_odd) == df['count']+idx = df.groupby(['Sp', 'Mt'])['count'].transform(max_odd) == df['count'] 
 +idx
 Out[5]: Out[5]:
 0     False 0     False
pandas_groupby.txt · Last modified: 2024/05/07 20:47 by raju