Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 18819

Reduce value of maximum value in multiple columns by one in pandas dataframe by group

$
0
0

Apologies - this is very similar to a query I had earlier but I was unable to delete as I'd made a mistake within it.

I simply want to find the maximum value by group in some of the columns (not all of them) in a dataframe - and reduce this grouped maximum value by one. It will be a single row, not multiple rows that have the maximum value.

So let's say I have a table with the following columns below. I want to reduce the maximum value by group (i.e. Name) in columns A, B and D by one:

Name A B C DBob  3 2 5 5Bob  4 9 7 7 Bob  6 0 1 3 Jim  7 0 7 9 Jim  1 3 9 1Jim  2 7 1 5

The end result I'm looking for is where the maximum value by column (for columns A, B and D) by group is reduced by one, per below - but column C remains untouched. Thanks.

Name A B C DBob  3 2 5 5Bob  4 8 7 6 Bob  5 0 1 3 Jim  6 0 7 8 Jim  1 3 9 1Jim  2 6 1 5

Viewing all articles
Browse latest Browse all 18819

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>