【问题标题】:I need to print the True values excluding Nan in a list in pandas dataframe我需要在熊猫数据框中的列表中打印不包括 Nan 的 True 值
【发布时间】:2019-09-18 09:59:35
【问题描述】:

我需要在 pandas 数据框中的列表中打印不包括 NaN 的 True 值。

dfa.where(dfa['Group']=='|Demographics')['Group']

【问题讨论】:

  • 你想要dfa.loc[dfa['Group']=='|Demographics', 'Group']吗?如果您只想要布尔数组,只需使用:dfa['Group']=='|Demographics'

标签: python pandas python-2.7


【解决方案1】:

听起来你需要的是

dfa[~dfa["Group"].isin(["|Demographics"]).isnull()]

isnull() 查找您的条件的 nan 值,但开头的 ~ 否定了这一点,因此产生非 nan 值。

【讨论】:

    【解决方案2】:

    试试这个,

    dfa1 = np.where ((dfa['Group']=='|Demographics') & (dfa['Group'] !=np.NaN)), dfa['Group'],'')
    
    dfa1
    

    【讨论】:

    • 快速良好的支持
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-30
    • 2018-07-08
    • 2023-01-28
    • 2018-12-18
    相关资源
    最近更新 更多