【问题标题】:Pandas - Indexing by not in indexPandas - 按不在索引中进行索引
【发布时间】:2015-11-04 08:20:08
【问题描述】:

用 Google 搜索了一下,似乎找不到任何关于此的内容。

是否可以使用“非索引”访问 pandas 数据框中的数据? 所以像

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'])

然后我希望能够调用以下命令以获取不在df_index 中的所有内容

df.ix[~df_index]

我知道您可以在 pandas 中进行逻辑索引。只是好奇我是否可以使用索引对象来做到这一点

【问题讨论】:

    标签: pandas indexing


    【解决方案1】:

    你可以使用df.drop(df_index, errors="ignore")

    【讨论】:

    • 很棒,很棒的想法。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-19
    • 1970-01-01
    • 2020-01-02
    • 1970-01-01
    • 1970-01-01
    • 2012-08-26
    相关资源
    最近更新 更多