0

This is an old question which is raised again because of pandas' deprecation.

[https://stackoverflow.com/questions/23108889/set-value-multiindex-pandas]

The previous provided solution doesnt work anymore. below is what it does now as the second param within loc now means column and not the nth multiindex.

>>> ticks = pd.DataFrame(index = multindex, columns = ['change'])
>>> ticks.loc[(p,1)] = 1
>>> ticks
                          change    1
datetime            2nd                                   
NaT                 NaN      NaN  NaN
2020-12-01 01:10:01          NaN  1.0
>>> ticks.loc[(p,2)] = 1
>>> ticks
                          change  1    2
datetime            2nd                                        
NaT                 NaN      NaN  NaN  NaN
2020-12-01 01:10:01          NaN  1.0  1.0

What is the new solution? and why the hell is such a crucial information not founded on pandas documentation?

smaillis
  • 298
  • 3
  • 12

1 Answers1

0

found the solution here an updated solution to "adding a row to a MultiIndex DataFrame/Series"
it is necessary to add the : to indicate all axes. i.e.

>>> ticks.loc[(p,2),:] = 1
smaillis
  • 298
  • 3
  • 12