You can use df.filter
with the regex
parameter:
df.filter(regex=r'(?i)^i')
this will return columns starting with I
ignoring the case.
Regex Demo
Example below:
Lets consider the input dataframe:
df = pd.DataFrame(np.random.randint(0,20,(5,4)),
columns=['itest','Itest','another','anothericol'])
print(df)
itest Itest another anothericol
0 1 4 14 17
1 17 10 14 1
2 16 18 10 7
3 10 12 17 14
4 6 15 17 19
With df.filter
print(df.filter(regex=r'(?i)^i'))
itest Itest
0 1 4
1 17 10
2 16 18
3 10 12
4 6 15
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…