【问题标题】:Removing empty dataframes inside a dictionary删除字典中的空数据框
【发布时间】:2020-03-18 23:32:58
【问题描述】:

我有一本名为 frames 的字典,其中包含数据框,它根据不同的因素总结了我的数据源。

其中一些组合返回空摘要,而这些数据框为空。

我的问题是如何从我的字典中删除这些空数据框? 我尝试了以下方法,但它们仍然存在。

new_frames = {k:v for (k,v) in frames.items() if v is not None}

谢谢

【问题讨论】:

标签: python pandas


【解决方案1】:

试试这个:

frames = {1: 10, 2: [], 3: []}

new_frames = {k:v for (k,v) in frames.items() if v != []}

new_frames
{1: 10}

如果你有 pandas 数据框:

new_frames = {k:v for (k,v) in frames.items() if not v.empty}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-26
    • 2022-01-15
    • 2016-11-12
    • 2021-10-31
    • 2016-11-13
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    相关资源
    最近更新 更多