Issue
I have a table like shown below
SKU | Stock | Past |
---|---|---|
ABC | 0 | 45 |
ABC | 20 | 30 |
DEF | 22 | 0 |
DEF | 5 | 67 |
Basically, I just want to change the value of 'Stock' and 'Past' to just one value and pick the highest, so the result should be:
SKU | Stock | Past |
---|---|---|
ABC | 20 | 45 |
DEF | 22 | 67 |
Is this possible to be done in Pandas? Please advise, anyone. Thank you very much!
Solution
You can groupby
"SKU" and use max
method to find the maximum value of each column in each group:
out = df.groupby('SKU').max()
Output:
Stock Past
SKU
ABC 20 45
DEF 22 67
Answered By - enke
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.