1

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?

1 Answer 1

1

Your approach seems a bit 'hacky', but you can use:

   for column in df:
     exec(column + '= df.at[0, column][column]')
Sign up to request clarification or add additional context in comments.

2 Comments

The created variable is always called column, therefore, in each iteration, the variable is being overridden.
Indeed, my bad. I changed it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.