在 pandas 中删除空列0.23+ [英] dropping empty columns in pandas 0.23+
问题描述
在早期版本的熊猫中,您可以使用以下简单的方法删除空列:
In earlier versions of pandas, you could drop empty columns simply with:
df.dropna(axis='columns')
但是,dropna在以后的版本中已被贬值.现在如何从数据框中删除多个(没有专门索引的)空列?
However, dropna has been depreciated in later builds. How would one now drop multiple (without specifically indexing) empty columns from a dataframe?
推荐答案
对于当前版本的Pandas(0.23.4),我可以使用dropna()
删除空列.我使用的代码是:
I am able to drop empty columns using dropna()
with the current version of Pandas (0.23.4). The code I used is:
df.dropna(how='all', axis=1)
好像不赞成使用的是一次通过多个轴(即df.dropna(how='all', axis = [0, 1]
).您可以在此处阅读,他们已经做出了这一决定-让我们弃用通过多个坐标轴,我们不会对其他任何熊猫函数执行此操作".
Looks like what is deprecated is passing multiple axes at once (i.e. df.dropna(how='all', axis = [0, 1]
). You can read here that they made this decision - "let's deprecate passing multiple axes, we don't do this for any other pandas functions".
这篇关于在 pandas 中删除空列0.23+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!