Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas - Indexing by not in index

Googled around a bit and couldn't seem to find anything on this.

Is there an option to access data in a pandas data frame using "not index"? So something like

df_index = asdf = pandas.MultiIndex(levels=[
['2014-10-19', '2014-10-20', '2014-10-21', '2014-10-22', '2014-10-30'],
[u'after_work', u'all_day', u'breakfast', u'lunch', u'mid_evening']],
labels=[[0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4],
[4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 2, 0, 1, 3, 4]],
names=[u'start_date', u'time_group'])

And then I would like to be able to call the following to get everything not in df_index

df.ix[~df_index]

I know you can do it for logical indexing within pandas. Just curious if I could do it using an Index Object

like image 396
archeezee Avatar asked Aug 11 '15 22:08

archeezee


1 Answers

you can use df.drop(df_index, errors="ignore").

like image 137
HYRY Avatar answered Oct 13 '22 10:10

HYRY