Reputation: 11741
I have a pandas
Series
that has many values indexed by strings. I want to grab all of them except for one.
my_series.ix['intercept'] #<--- this has the value I don't want
Is there a way to grab everything in my_series
except for what is returned by my_series.ix['intercept']
?
Upvotes: 5
Views: 3598
Reputation: 881027
You could construct a mask
-- a boolean array which is True where the Series index equals the particular value:
mask = my_series.index.isin(['intercept'])
Then you could select the remaining rows in the typical fashion:
my_series.loc[~mask]
Note that if the value occurs in the index more than once, then all rows with the same index will be removed:
my_series = pd.Series([10,20,30,40], index=['foo','intercept','baz','intercept'])
# foo 10
# intercept 20
# baz 30
# intercept 40
# dtype: int64
mask = my_series.index.isin(['intercept'])
print(my_series.loc[~mask])
yields
foo 10
baz 30
dtype: int64
Upvotes: 9