【发布时间】:2016-11-17 10:24:22
【问题描述】:
我有一个这样的列表:
{291840: ['http://www.rollanet.org', 'http://www.rollanet.org'],
291841: ['http://www.superpages.com', 'http://www.superpages.com],
291848: ['http://www.drscore.com/App/ScoreDr', 'http://www.drscore.com'],...etc }
我想将其转换为两列数据框,一列用于subj_id,另一列用于对应列表。每行将是字典的键,列是使用from_dict 将方向设置为索引的值(列表)。根据文档:“orient:如果键应该是行,则传递‘index’。”
names = ['subj_id', 'URLs']
dfDict = pd.DataFrame(columns = names)
dfDict.from_dict(listDict, orient = 'index')
相反,我得到一个数据框,其中将列表的每个元素作为一列。我只想要两列。一个用于subj_ID,另一个用于与subj_ID 关联的URL 列表。
【问题讨论】:
标签: python pandas dictionary