熊猫df。申请包括NAN值的条件
我正在尝试使用应用方法和lambda函数和属性过滤的pandas.dataframe在我的pandas.dataframe中替换异常值和NAN值。我尝试了三种不同的方式,但似乎并没有捕获NAN值的案例。
df.apply( lambda row: mode
if (row['prop1']>quart95 or row['prop1']==np.nan) and row['prop2']=='some_value'
else row['prop1'], axis=1 )
df.apply( lambda row: mode
if (row['prop1']>quart95 or row['prop1']==None) and row['prop2']=='some_value'
else row['prop1'], axis=1 )
df.apply( lambda row: mode
if (row['prop1']>quart95 or not row['prop1']) and row['prop2']=='some_value'
else row['prop1'], axis=1 )
为什么要找到异常值,但与NAN一起工作? 我该如何修复或这样做?
I'm trying to replace outliers and NaN values in my pandas.DataFrame with the mode of the series, using the apply method and a lambda function and filtering by a property. I've tried in three different ways but it doesn't seems to capture the cases with NaN values.
df.apply( lambda row: mode
if (row['prop1']>quart95 or row['prop1']==np.nan) and row['prop2']=='some_value'
else row['prop1'], axis=1 )
df.apply( lambda row: mode
if (row['prop1']>quart95 or row['prop1']==None) and row['prop2']=='some_value'
else row['prop1'], axis=1 )
df.apply( lambda row: mode
if (row['prop1']>quart95 or not row['prop1']) and row['prop2']=='some_value'
else row['prop1'], axis=1 )
Why it works finding the outliers but it doesn't with the NaNs ?
How could I fix it or do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设
模式
是一个值(不是列表):您可以使用
bitwise或Operator(|)
来执行此条件。 PLESE,请参阅此链接以了解更多有关位的操作员。supposing
mode
is a single value (not a list):You can use the
bitwise OR operator (|)
to do this condition. Plese, refer to this link to understand more about bitwise operators.