The following is a minimal example of what I am trying to do. I have a pandas DataFrame with multiindex as follows
import pandas as pd
import numpy as np
arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
tuples = list(zip(*arrays))
index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])
s = pd.DataFrame(np.random.randn(8,2), index=index)
So the DataFrame I have is
0 1
first second
bar one -3.174428 -0.314160
two 0.968316 0.278967
baz one 0.171292 -0.789257
two 1.420621 0.100964
foo one -1.001074 -0.517729
two -0.211823 0.951422
qux one 1.173289 0.313692
two -0.159855 0.149710
What I want is to set all the observations with the index "second" equal to two as -1. What I have in mind is using .loc, something as follows:
s.loc[(:,'two')]
but .loc would not accept the ":" operator.
Could someone help here?