Update pandas dataframe with multiindex based on conditions

Viewed 37

trying to update the dataframe:

hist.loc['2021-01-20':'2021-01-22']

before update

, but with

hist.loc['2021-01-20':'2021-01-22']['ETH-USD']['nof'] = 1

I still get the same:

after update

I would expect to have "1"-s in the "nof" column of "ETH-USD" after the update, but there are still "0"-s. Why is that, and how to solve it?

Thanks, Balazs

1 Answers

Use tuples in DataFrame.loc for select by MultiIndex:

hist.loc['2021-01-20':'2021-01-22', ('ETH-USD', 'nof')] = 1

Why your solution failed is better explain here.

Related