In view of automation I would like to integrate a f-string in variable names and call in a loop those variables. More precisely, let one of the variables be:
structure_acronym = ['Ocx', 'M1C-S1C', 'AMY', 'MGE', 'STC','MGE', 'URL', 'CGE', 'DTH', 'MFC', 'DFC']
For each of these acronyms I have to build a data frame out of a larger data frame. The larger data frame contains in it's column names structure acronyms that are repeated. Each smaller data frame that I want to build will contain a subselection of columns will comprise a single acronym in its column names but which is repeated. Each of such data frames will go into a pipeline which leads to k-means clustering. The variables such as f'new_column_name_cluster_{structure}'
, f'{structure}_df'
will be used in the pipeline. Here is a loop that I am building but which raises the exception invalid syntax pointing to the f-string.
names=larger_dataframe.columns
for structure in structure_acronym:
f'new_column_name_cluster_{structure}' = ['ensembl_gene_id','gene_symbol']+[name for name in names if structure in name]
f'{structure}_df' = larger_dataframe[f'new_column_name_cluster_{structure}']
Can somebody help me out to make the code run ? Thanks.