Suppose I construct the following dataframe:
a = pd.DataFrame({'a':np.arange(5)})
b = pd.DataFrame({'b':np.arange(4)})
c = pd.DataFrame({'c':np.arange(5)})
d = pd.DataFrame({'d':np.arange(7)})
df = pd.concat([a,b,c,d,],ignore_index=False, axis=1)
This produce the following dataframe:
df
Out[86]:
a b c d
0 0.0 0.0 0.0 0
1 1.0 1.0 1.0 1
2 2.0 2.0 2.0 2
3 3.0 3.0 3.0 3
4 4.0 NaN 4.0 4
5 NaN NaN NaN 5
6 NaN NaN NaN 6
How can I remove all columns that have a length of exactly 5 numerical elements without using dropna?
The output will be:
df
Out[88]:
a c
0 0.0 0.0
1 1.0 1.0
2 2.0 2.0
3 3.0 3.0
4 4.0 4.0