gpt4 book ai didi

python - 删除 Pandas 数据框中的 NaN/NULL 列?

转载 作者:IT老高 更新时间:2023-10-28 20:29:36 32 4
gpt4 key购买 nike

我在 pandas 中有一个 dataFrame,其中几列都有空值。是否有内置函数可以让我删除这些列?

最佳答案

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

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')

关于python - 删除 Pandas 数据框中的 NaN/NULL 列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10857924/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com