I know we can select only few columns using pandas dataframe filter, but can we also exclude only some columns?
Here is MWE:
import numpy as np
import pandas as pd
df = pd.DataFrame({'id': [1,2,3], 'num_1': [10,20,30], 'num_2': [20,30,40]})
df.filter(regex='num')
Can we select all columns not having 'num' in the columns:
Something like:
df.filter(regex='^(num)')
Required Output
id
0 1
1 2
2 3
Note
# these already works, i am only looking regex way
df[['id']] # gives the required output
Reference:
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.filter.html