I'm trying to make my code more elegant and I realized I may be doing some unnecessary coding. I have many variables entitled things like trust_1, trust_2, trust_3, etc. up to 25. I'm creating a new data frame made up of these variables in pandas.
df = df1[['trust_1', 'trust_2', 'trust_3', 'trust_4', 'trust_5' ]]
I was wondering if I could use regular expressions or something that takes the place of the number and will keep all the variables. For example,
df = df1[['trust_\d+']]
that would do the same thing as above. Is there a way?