python dataframe drop null值_删除Pandas数据框中的NaN/NULL列?

下面是一个简单的函数,您可以通过传递dataframe和threshold直接使用它df

”’

pets location owner id

0 cat San_Diego Champ 123.0

1 dog NaN Ron NaN

2 cat NaN Brick NaN

3 monkey NaN Champ NaN

4 monkey NaN Veronica NaN

5 dog NaN John NaN

”’def rmissingvaluecol(dff,threshold):

l = []

l = list(dff.drop(dff.loc[:,list((100*(dff.isnull().sum()/len(dff.index))>=threshold))].columns, 1).columns.values)

print(“# Columns having more than %s percent missing values:”%threshold,(dff.shape[1] – len(l)))

print(“Columns:\n”,list(set(list((dff.columns.values))) – set(l)))

return l

rmissingvaluecol(df,1) #Here threshold is 1% which means we are going to drop columns having more than 1% of missing values

output

”’

Columns having more than 1 percent missing values

Original: https://blog.csdn.net/weixin_28723109/article/details/112964109
Author: 宋世泊
Title: python dataframe drop null值_删除Pandas数据框中的NaN/NULL列?

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/679571/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球