I have a column where its categorical (house, neighbors, routine). And I have 4 extra columns. The dataset looks like this:
print(df)
type num_before_cleaning num_after_cleaning num_before_removing num_after_removing
0 house 32 12 42 10
1 house 10 3 4 1
2 neighbors 20 5 25 7
3 routine 40 21 62 35
4 neighbors 14 2 21 9
5 routine 52 30 71 42
and I want for each category in column type it will divide num_before_cleaning / num_after_cleaning and num_before_removing / num_after_removing
So, the outcome will be for example:
print(house_cleaning)
0.64
print(routine_removing)
0.79
I know that I should use np.where but how can I make it perform calculations after giving it a specific condition? Or is there any other ways I can solve it.
I've tried researching but didn't find any answers.
type, it will divide what ends with cleaning so it will calcuate the sum ofnum_before_cleaningand divide it by the sum ofnum_after_cleaning. And same goes toremoving.