首页 > 解决方案 > 根据每个值的关联值从字典创建映射

问题描述

我有以下类型的字典:

{ 'Publisher_name': [( 'Sun Publications', '0')],  'Author_Book Ratio': [(1.27364726,  '00')
, (0.765346483,  '01')],  'Book_series_no': [(1,  '000'), (2,  '001'), 
(1,  '010'), (2,  '011')],  'Volume_No': [(1,  '0010'), (2,  '0011')],
'publishing_status': [( 'Y',  '000'), ( 'Y',  '001'), ( 'N',  '010'), ( 'Y',  '011')],  
'Volume_name': [( 'Perils of Annoyance Vol.1',  '0010'), ( 'Perils of Annoyance Vol.2',  '0011')],
  'Book_name': [( 'Thoughts of a River Bound Duck',  '000'),
 ( 'Perils of Annoyance',  '001'), ( 'Welcome to the Valley',  '010'),
 ( 'Open the box',  '011')],  'Author_name': [( 'August Oliver',  '00'),
 ( 'Pierce Rhombus',  '01')],  'Author_ID': [(3,  '00'), (2,  '01')],
  'timestamp': [( '01-Aug-17 13:25:32', '0')]}

每个值附带的数字描述了元素所属的级别和父级。带有“00”的作者详细信息表示它属于第“0”个出版商,是“1”的作者,“001”表示该书属于第0个出版商,第0个作者,是他的第0本书。所有的值都是相似的。如果特定父节点或子节点没有值,则该列将填充为空。我想从这个字典中创建一个数据框,它将是以下排序-

+----------------+------------------+--------------+-----------------+---------+------------------------------+--------------+-----------------+-------------------------+---------+
|  Publisher_name|         timestamp|   Author_name|Author_Book_Ratio|Author_ID|                     Book_name|Book_series_no|publishing_status|              Volume_name|Volume_No|     
+----------------+------------------+--------------+-----------------+---------+------------------------------+--------------+-----------------+-------------------------+---------+
|Sun Publications|01-Aug-17 13:25:32| August Oliver|       1.27364726|        3|Thoughts of a River Bound Duck|             1|                Y|                     Null|     Null|
|Sun Publications|01-Aug-17 13:25:32| August Oliver|       1.27364726|        3|           Perils of Annoyance|             2|                Y|Perils of Annoyance Vol.1|        1|
|Sun Publications|01-Aug-17 13:25:32| August Oliver|       1.27364726|        3|           Perils of Annoyance|             2|                Y|Perils of Annoyance Vol.2|        2|
|Sun Publications|01-Aug-17 13:25:32|Pierce Rhombus|      0.765346483|        2|         Welcome to the Valley|             1|                N|                     Null|     Null|
|Sun Publications|01-Aug-17 13:25:32|Pierce Rhombus|      0.765346483|        2|                  Open the box|             2|                Y|                     Null|     Null|
+----------------+------------------+--------------+-----------------+---------+------------------------------+--------------+-----------------+-------------------------+---------+

如何做到这一点?

标签: pythonpandasdictionarydataframe

解决方案


推荐阅读