Skip to content
Advertisement

Groupby with multiindex replacement

For a given date, how can I replace missing UK values with the US value? Need in general code.

JavaScript

Expected Output

JavaScript

Advertisement

Answer

You can select by lists for avoid remove MultiIndex and for correct align is used rename:

JavaScript

Or reshape by DataFrame.unstack, replace by rows and reshape back:

JavaScript

JavaScript

EDIT: If want use solution only of all NaNs solution is test it for scalar True or False:

JavaScript

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