I want to create 6 pandas dataframes from 6 text files. I want to name them according to the names of the text files. The text files are named as 'DAPC_min.txt' and so on. I want the dataframe names as 'DAPC_data' and so on.
import pandas as pd
lipids = ['DAPC', 'DIPC', 'DLPC', 'DOPC', 'DPPC', 'POPC']
for lipid in lipids:
'{}_data'.format(lipid) = pd.read_csv(
'{}_min.txt'.format(lipid),
delimiter=' ', names=['bead_type', 'z_min', 'gz_min', 'dGwm'])
But I am getting the following error message:
'{}_data'.format(lipid) = pd.read_csv(
^
SyntaxError: can't assign to function call
What I am doing wrong?
dct = {}and then inside the loop, change the left hand side to:dct['{}_data'.format(lipid)] = pd.read_csv(...)The way you are currently doing is possible in some languages (with some hacks in Python too) but using a dictionary in these situations is strongly recommended.