先创建一个数据框:
import pandas as pd
df = pd.DataFrame({'a':[1,1,np.nan,np.nan,4], 'b':[5,6,np.nan,8,np.nan]})
删除特定值存在的行
数据框删去特定值所在行:
df1 = df.drop(df[df['a']==4].index, inplace = True)
删除存在空值的行
删除有空值的所有行:
df1 = df.dropna()
删除a列为空值的所有行:
df1 = df.dropna(subset = ['a'])
删除a列或b列为空值的所有行:
df1 = df.dropna(subset = ['a','b'], how = any)
删除a和b都为空值的所有行:
df1 = df.dropna(subset = ['a','b'], how = all)
删除存在空值的列
删除存在空值的所有列:
df1 = df.dropna(axis = 1)
标签:删除,Python,nan,df1,dropna,空值,--,df
From: https://blog.csdn.net/wodertianna/article/details/139480605