Reputation: 389
I created a dataframe (called df) with few columns (for example 3 columns with the following names: 'data', 'SID' and 'time'). df has only one row. Each cell of the data frame contains a dictionary built as follow:
{'column_name': ndarray}
For example, the dictionary at the SID column is like this:
{'SID': ndarray}
I would like to access/extract the ndarrays stored in the dictionaries and assign each one of them to a new variable called after the column name as follows:
data = df.at[0, 'data']['data']
SID = df.at[0, 'SID']['SID']
time = df.at[0, 'time']['time']
I'm asking for a generic/iterative way to do it. Any idea?
Upvotes: 1
Views: 2405
Reputation: 131
Your approach seems a bit 'hacky', but you can use:
for column in df:
exec(column + '= df.at[0, column][column]')
Upvotes: 1