在Python中将有序字典转换为新列

在Python中将有序字典转换为新列,python,pandas,ordereddictionary,Python,Pandas,Ordereddictionary,在我的dataframe中,一些列采用OrderedDictionary格式。如何将它们转换为新列(不知道哪些列包含OrderedDictionary和OrderedDictionary中的元素) 示例列: inventors [OrderedDict([('@sequence', '001'), ('@app-type', 'applicant'), ('@designation', 'us-only'), ('addressbook', OrderedDict([('last-name',

在我的dataframe中,一些列采用OrderedDictionary格式。如何将它们转换为新列(不知道哪些列包含OrderedDictionary和OrderedDictionary中的元素)

示例列:

inventors
[OrderedDict([('@sequence', '001'), ('@app-type', 'applicant'), ('@designation', 'us-only'), ('addressbook', OrderedDict([('last-name', 'Nahm'), ('first-name', 'Seung Hoon'), ('address', OrderedDict([('city', 'Daejeon'), ('country', 'KR')]))])), ('residence', OrderedDict([('country', 'KR')]))]), OrderedDict([('@sequence', '002'), ('@app-type', 'applicant'), ('@designation', 'us-only'), ('addressbook', OrderedDict([('last-name', 'Jang'), ('first-name', 'Hoon Sik'), ('address', OrderedDict([('city', 'Daegu'), ('country', 'KR')]))])), ('residence', OrderedDict([('country', 'KR')]))])]
我想将其转换为以下数据帧(未写入所有列):


在本例中,last_name和first_name来自另一个嵌套字典。在数据中,我不知道哪些列包含OrderedDictional,为了简单起见,我只包含了数据集中的一列,即inventors,您考虑过pandas函数了吗

# Create example dict
import collections
inventors = collections.OrderedDict()
inventors['@sequence'] =  "001"
inventors['@app-type'] =  "applicant"
inventors['@designation'] =  "us-only"
inventors['last-name'] =  "Nahm"
inventors['first-name'] =  "Seung Hoon"

# Import pandas to use from_dict function
import pandas as pd

# Use from_dict() function; include orient='index' for now to avoid index error
df = pd.DataFrame.from_dict(inventors, orient='index')

# Transpose for final output
df.T

df=pd.DataFrame(发明人[0])
?你没有说
@
去哪里,也没有包括本身是嵌套字典的列让我来编辑这个问题
# Create example dict
import collections
inventors = collections.OrderedDict()
inventors['@sequence'] =  "001"
inventors['@app-type'] =  "applicant"
inventors['@designation'] =  "us-only"
inventors['last-name'] =  "Nahm"
inventors['first-name'] =  "Seung Hoon"

# Import pandas to use from_dict function
import pandas as pd

# Use from_dict() function; include orient='index' for now to avoid index error
df = pd.DataFrame.from_dict(inventors, orient='index')

# Transpose for final output
df.T