79637679

Date: 2025-05-25 12:54:14
Score: 0.5
Natty:
Report link

I have found a way to get my table, but not very elegant nor practical, I guess there is a more simple solution with some proper pandas function. Here is the solution, but if you have a better i.e. more "pandas-ic" way to do it, I would be very interested!

df = df_initial.set_index(['State', 'Capital', 'Year', 'Type of residence']).groupby("Metric")
numerator = df.get_group("Squared meters").drop(columns=["Metric"])
denominator = df.get_group("Nb rooms").drop(columns=["Metric"])
ratio = numerator.div(denominator).reset_index()
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Lucas