I need to select columns in Pandas which contain only numeric values in column names, for example:
df=
0 1 2 3 4 window_label next_states ids
0 17.0 18.0 16.0 15.0 15.0 ddddd d 13.0
1 18.0 16.0 15.0 15.0 16.0 ddddd d 13.0
2 16.0 15.0 15.0 16.0 15.0 ddddd d 13.0
3 15.0 15.0 16.0 15.0 17.0 ddddd d 13.0
4 15.0 16.0 15.0 17.0 NaN ddddd d 13.0
so I need to select only first five columns. Something like:
df[df.columns.isnumeric()]
EDIT
I came up with the solution:
digit_column_names = [num for num in list(df.columns) if isinstance(num, (int,float))]
df_new = df[digit_column_names]
not very pythonic or pandasian, but it works.