删除Pandas数据框中的NaN/NULL列? [英] Remove NaN/NULL columns in a Pandas dataframe?

查看:211
本文介绍了删除Pandas数据框中的NaN/NULL列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在熊猫中有一个dataFrame,并且其中几列的值均为空.有内置的功能可以让我删除那些列吗?

I have a dataFrame in pandas and several of the columns have all null values. Is there a built in function which will let me remove those columns?

推荐答案

是的,dropna.参见 http://pandas.pydata.org/pandas-docs/stable/missing_data.html DataFrame.dropna文档字符串:

Yes, dropna. See http://pandas.pydata.org/pandas-docs/stable/missing_data.html and the DataFrame.dropna docstring:

Definition: DataFrame.dropna(self, axis=0, how='any', thresh=None, subset=None)
Docstring:
Return object with labels on given axis omitted where alternately any
or all of the data are missing

Parameters
----------
axis : {0, 1}
how : {'any', 'all'}
    any : if any NA values are present, drop that label
    all : if all values are NA, drop that label
thresh : int, default None
    int value : require that many non-NA values
subset : array-like
    Labels along other axis to consider, e.g. if you are dropping rows
    these would be a list of columns to include

Returns
-------
dropped : DataFrame

要运行的特定命令为:

df=df.dropna(axis=1,how='all')

这篇关于删除Pandas数据框中的NaN/NULL列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆