I have a pandas DF with 5000 rows and 400+ columns containing identifiers as an index column with the remaining columns containing key value pairs in the form of a dictionary.
eg.
Identifier 0 1
identifier 1 {'key':'value'} {'key2':'value2'}
I'm trying to get to a point where the data looks like this:
Identifier key key2
identifier1 value value 2
I know we can use the following in order to create a df from a nested dictionary:
df = pd.DataFrame(data).T
But that would require the data to look like this:
data = {'Identifier1': {'key': 'value', 'key2': 'value2'}}
When i use df.to_dict() on my current dataframe in order to get it to the above format, it looks like so:
{'Identifier1':{'0': {'key':'value'}, '1': {'key1':'value1'}...}}
Which I understand why. My question is two fold I suppose:
How can I get my data to a place where df = pd.DataFrame(data).T works ? Is there a better way to go about this?
EXAMPLE as requested:
Data looks like this:
| FileID | 0 | 1 |
|---|---|---|
| file1 | {'key1':value1} | {'key3':value1} |
| file2 | {'key2':value1} | {'key1':value2} |
I'd like it to look like this:
| FileID | key 1 | key2 | key3 |
|---|---|---|---|
| file1 | value1 | value1 | |
| file2 | value2 | value 1 |
EDIT 2: There are nonetypes within the dataframe I am working with as well. In trying out the solutions myself, I've come to realize that. Apologies for not including that information initially.

