Skip to content
Advertisement

Map 2 df but column to value instead of value to value for each ID

I have a table with top 3 reasons (Table 1) and another table with the category it belongs to for each variable (Table 2). I am trying to match the category bins into the reason table like in table 3.

JavaScript

Advertisement

Answer

Approach

  • index two data frames in way that works with join()
  • then it’s a pd.concat() of each of the reasons from output of join
JavaScript
RegNo Reason1 Reason2 Reason3
1111 (0.0, 60.0] (0.44, 0.64] (102.0, 175.0]
2222 (-inf, 0.33] (0.0, 60.0] missing
3333 (0.0, 60.0] (0.44, 0.64] missing
4444 (0.0, 60.0] (20.0, 102.0] (0.44, 0.64]
5555 (0.0, 60.0] (0.64, inf] missing
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement