Issue
In my python dataframe I have around 40 columns. Out of these 40 columns around 20 columns starts with "Name_"
for example "Name_History","Name_Language
" and remaining column starts with "score_"
for example "Score_Math","Scor_Physisc".
I would like to determine dynamically First & last index of columns starting with "Name_"
.
Solution
You can do this to return an array with first and last:
df.columns[df.columns.str.startswith('Name_')][[0,-1]]
Answered By - Scott Boston
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.