I have a weird problem: I am trying to add a new row in my table with multi-indeces. However, even though I do it exactly as solved in here: adding a row to a MultiIndex DataFrame/Series . Their example and solution works, but it does not work with my data. Either I am doing something wrong, or there is a bug
import pandas as pd
import datetime as dt
Their code (working):
df = pd.DataFrame({'Time': [dt.datetime(2013,2,3,9,0,1), dt.datetime(2013,2,3,9,0,1)],
'hsec': [1,25], 'vals': [45,46]})
df.set_index(['Time','hsec'],inplace=True)
print df
df.ix[(dt.datetime(2013,2,3,9,0,2),0),:] = 5
print df
Output:
vals
Time hsec
2013-02-03 09:00:01 1 45
25 46
and
vals
Time hsec
2013-02-03 09:00:01 1 45
25 46
2013-02-03 09:00:02 0 5
My code (not working):
d = [[0, 0, 2], [0, 2, 2], [1, 0, 2], [1, 2, 2]]
df = pd.DataFrame(d, columns=('frames', 'classID', 'amount'))
df.set_index(['frames', 'classID'], inplace=True)
print df
df.ix[(1,1),:] = 5
print df
Output:
amount
frames classID
0 0 2
2 2
1 0 2
2 2
and
amount
frames classID
0 0 2
2 5
1 0 2
2 2
Note the 5
appeared at df.loc[(0,2)]
!