Skip to content
Advertisement

How to calculate comparison highest value to lowest value in pandas dataframe

Here’s my dataset

JavaScript

Here’s my expected output Comparison is the highest comparing to the lowest age group

JavaScript

Note:

a.age is index column

Comparison had 1.020994624671123 value is come from 0.973257/0.953244, 15-20 compare to 35-50

Comparison had 1.020994624671123 value is come from 0.943649/0.890820, <15 compare to 35-50

Advertisement

Answer

Aggregate age like columns with min and max along axis=1, then divide max / min value to calculate ratio:

JavaScript

JavaScript

Note: I am assuming that column a.age is already set as the index of dataframe.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement