pandas处理缺失值df.dropna( )的thresh参数

转载自:https://www.cnblogs.com/zeng-ymzkx/p/11468912.html

df.dropna( thresh = n )

理解:这一行除去NA值,剩余数值的数量大于等于n,便显示这一行。

import numpy as np
from numpy import nan as NA

import pandas as pd
from pandas import Series,DataFrame

df = pd.DataFrame (np.random .randn(8,7))

df.iloc[0,:] = NA
df.iloc[1,:6] = NA
df.iloc[2,:5] = NA
df.iloc[3,:4] = NA
df.iloc[4,:3] = NA
df.iloc[5,:2] = NA
df.iloc[6,0] = NA

结果:

 

 END

 

 

验证:

(1)n=1,即剔除NA值,这些行剩余的数值数量大于等于1

df.dropna(thresh=1)

 

 END

 

(2)n=3,即剔除NA值,这些行剩余的数值数量大于等于3

df.dropna(thresh=3)

 

 END

 

 

(3)n=6,即剔除NA值,这些行剩余的数值数量大于等于6

df.dropna(thresh=6)

 

  END

 

posted @ 2020-04-25 00:35  limalove  阅读(3406)  评论(0编辑  收藏  举报