我想根据我的熊猫数据框中的第一个索引值进行条件替换。如果我有一个数据帧,例如:替换熊猫多索引数据帧中的列值
from pandas import *
arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
tuples = zip(*arrays)
index = MultiIndex.from_tuples(tuples, names=['first','second'])
data = DataFrame(randn(8,2),index=index,columns=['c1','c2'])
我想我应该能够通过列替换值:
data.ix['bar']['c1'] = -999
但这返回原始数据框中,持平。任何人都可以解释这应该怎么做,为什么我目前的方法不起作用?
您可能更喜欢使用NaN来查找缺失的数据。 –
@AndyHayden - 真的够了,我可能会用NaN。我只是在这里选择了-999这个例子。 – tnknepp