axis:{0或者‘index’, 1或者‘columns’}, 默认0
确定是否删除包含缺失值的行或列。
how: {‘any’,‘all’},默认为’any’
当我们有至少一个NA或全部为 NA时,确定是否从DataFrame中删除行或列。
thresh:int,可选
需要许多非NA值
subset:array-like, 可选
要考虑的其他轴上的标签,例如,如果要删除行,这些标签将是要包括的列的列表。
inplace:bool, 默认为False
如果为True,则执行就地操作并返回None。
Returns:DataFrame
删除了NA条目的DataFrame
df = pd.DataFrame({"name": ['Alfred', 'Batman', 'Catwoman'],
... "toy": [np.nan, 'Batmobile', 'Bullwhip'],
... "born": [pd.NaT, pd.Timestamp("1940-04-25"),
... pd.NaT]})
>>> df
name toy born
0 Alfred NaN NaT
1 Batman Batmobile 1940-04-25
2 Catwoman Bullwhip NaT
>>> df.dropna()
name toy born
1 Batman Batmobile 1940-04-25
>>> df.dropna(axis='columns')
name
0 Alfred
1 Batman
2 Catwoman
>>> df.dropna(how='all')
name toy born
0 Alfred NaN NaT
1 Batman Batmobile 1940-04-25
2 Catwoman Bullwhip NaT
>>> df.dropna(thresh=2)
name toy born
1 Batman Batmobile 1940-04-25
2 Catwoman Bullwhip NaT
>>> df.dropna(subset=['name', 'born'])
name toy born
1 Batman Batmobile 1940-04-25
>>> df.dropna(inplace=True)
>>> df
name toy born
1 Batman Batmobile 1940-04-25