'python convert string list into a dataframe list
I have a list of string dataframes that I want to turn into a list of dataframes.
temp_df = {}
temp_df['mdf1'] = df1[df1['b']<=0.4]
temp_df['mdf2'] = df1[df1['a']<=0.58]
def get_list(temp_df):
return [*temp_df]
temp_list = get_list(temp_df)
temp_list
Doing this I get the stringed list:
output: ['mdf1', 'mdf2']
However, I also want a list of the two dataframes itself. For the desirable output of:
output: [mdf1, mdf2]
I've tried this but it doesn't give me what I want:
temp_df.keys()
output: dict_keys(['mdf1', 'mdf2'])
Solution 1:[1]
Check with locals then
variables = locals()
variables["mdf1"] = df1[df1['b']<=0.4]
variables["mdf2"] = df1[df1['a']<=0.58]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BENY |
