DataFrame.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)
Remove missing values.
See the User Guide for more on which values are considered missing,
and how to work with missing data.
Returns
DataFrame
DataFrame with NA entries dropped from it.
2 功能
dropna()函数用于删除dataframe数据中的确实数据,即删除Nan数据。
3 参数说明
axis:删除数据的维度,默认为0
how:{“any”, “all”},any:删除含有Nan的行,all:删除全为nan的行
thresh:int,保留至少thresh个非Nan行
subset:list,在特定列缺失值处理
inplace:是否修改源文件
4 举例
代码如下:
import pandas as pd
import numpy as np
df = pd.DataFrame({"name":['Alfred','Batman','Catwoman'],"toy":[np.nan,'Batmobile','Bullwhip'],"born":[pd.NaT, pd.Timestamp("1940-04-25"), pd.NaT]})print(df)
df_new = df.dropna()print(df_new)
原数据: 【预期是要删除掉第0行、第2行】
name toy born
0 Alfred NaN NaT
1 Batman Batmobile 1940-04-252 Catwoman Bullwhip NaT
文章目录1 函数原型2 功能3 参数说明4 举例1 函数原型DataFrame.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False) Remove missing values. See the User Guide for more on which values are considered missing, and how to work with missing data.Returns DataFr