R(complete.cases)
rm(list=ls())
# 创建一个包含缺失值的数据框
# df <- data.frame(
# x = c(1, 2, NA, 4),
# y = c(NA, 2, 3, 4),
# z = c(1, NA, 3, 3)
# )
#
# # 使用complete.cases函数筛选包含缺失值的数据行
# missing_rows <- !complete.cases(df)
#
# # 打印包含缺失值的数据行
# print(df[missing_rows, ])
# create a data frame from scratch
age <- c(25, 999, 56,NA)
gender <- c("male", "female", "male", "male")
weight <- c(160, NA,110, 220)
mydata <- data.frame(age,gender,weight)
#print(mydata)
aa =mydata[complete.cases(mydata),] ## 直接取不缺少的行就可以了
print(aa)
结果如下
python(pd.dropna)
import pandas as pd
import numpy as np
df = pd.DataFrame({"age":[25,999,56,pd.NA],"gender":["male","female","male","male"],
"weight":[160,pd.NA,110,220]})
print(df)
# df = pd.DataFrame({"a": [0, pd.NA, 2], "b": [0, np.nan, 2]})
# df
df.dropna(axis = 0, how = 'any', inplace = True)
print(df)