I have this pandas dataframe:
d=pandas.DataFrame([{"a": 1}, {"a": 3, "b": 2}])
and I'm trying to add a new column to it with non-null values only for certain rows, based on their numeric indices in the array. for example, adding a new column "c" only to the first row in d:
# array of row indices
indx = np.array([0])
d.ix[indx]["c"] = "foo"
which should add "foo" as the column "c" value for the first row, and NaN for all other rows. but this doesn't seem to change the array:
d.ix[np.array([0])]["c"] = "foo"
In [18]: d
Out[18]:
a b
0 1 NaN
1 3 2
what am I doing wrong here? how can it be done? thanks.