简体   繁体   English

根据条件对df进行分段显示jupyter中的nan值

[英]Segmenting a df based on condition shows nan values in jupyter

Using df[columns][df[colums]<0.5] to segment a DataFrame in Pandas usually only showed me the rows matching this condition. 使用df[columns][df[colums]<0.5]分割Pandas中的DataFrame通常只向我显示匹配此条件的行。

Just recently I end up getting NaN - Values shown: 就在最近,我最终得到NaN-显示的值:

在此处输入图片说明

Was there an update I'm missing or what is causing this behaviour usually? 我是否缺少更新,或者通常是什么导致此行为?

Dropping all NaN with .dropna() is obviously a fast solution to this issue, but doesn't explain the change in "behaviour". 使用.dropna()删除所有NaN显然是解决此问题的快速方法,但没有解释“行为”的更改。

Fix: Don't put columns in double brackets.. 修正:不要将列放在双括号中。

如果需要按一列进行比较并按多列进行过滤,请使用带有boolean indexing DataFrame.loc

df.loc[df['district-heating'] < 0.5, ['id','district-heating']]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM