本文介绍了在dropna之后不删除Nans的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据帧为400 x25.我应该从数据集中删除所有Nan,然后从25列中只选择要处理的3列.我使用以下方法完成此操作:

i have a dataframe of 400 x 25. i am supposed to remove ALL Nans from the dataset and then select only 3 columns to work on from the 25 columns. I have done this using:

df1.dropna(axis=0)
df2=df1.loc[:,['bgr','wc','rc']]
df2['rc']=pd.to_numeric(df['rc'],errors='coerce')
df2['wc']=pd.to_numeric(df['wc'],errors='coerce')

当我执行dtypes时,rc和wc显示为对象,所以我将它们转换为浮点数.

rc and wc were showing up as objects when i did the dtypes, so i converted them to floats.

现在,在放下Nans之后,我只剩下252行.所以我以为所有的Nans都走了.

now, after i drop the Nans, i am left with only 252 rows. so i assumed that all the Nans had gone.

但是当我执行df2.describe()时,它显示rc为251,而bgr和wc为252.这很奇怪,所以当我执行df2.rc.unique()时,它显示了Nan !!!

but when i did a df2.describe(), it showed 251 as count for 'rc' but 252 for 'bgr' and 'wc'. this was odd, so when i did a df2.rc.unique(), it showed up a Nan!!!!

我的问题:如何删除这个Nan?

my question: how do i remove this Nan??

推荐答案

重新分配:

df = df.dropna(axis=0)

默认情况下,它不是就位的,除非您这样说:

by default it's not inplace unless you say so:

df.dropna(axis=0, inplace=True)

检查文档

这篇关于在dropna之后不删除Nans的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 11:31