I'm trying to subset column names into a range of lists and I can do it one by one but given I want to do more than 10, I am trying to use a loop with f-string. But mine didn't seem to work. How can I do this with f-string and a loop?
a1_cols = [col for col in df.columns if 'a1_' in col]
a2_cols = [col for col in df.columns if 'a2_' in col]
a3_cols = [col for col in df.columns if 'a3_' in col]
...
a10_cols = [col for col in df.columns if 'a10_' in col]
for i in range(1, 12):
f'a{i}_cols' = [col for col in df.columns if f'a{i}_' in col]