根据每个值的关联值从字典创建映射

2024-10-05 11:22:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一本下列词典:

{ '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本书。所有的值都是相似的。如果没有特定父节点或子节点的值,则该列将填充为null。我想从这本字典中创建一个数据帧,它的类型如下-

+----------------+------------------+--------------+-----------------+---------+------------------------------+--------------+-----------------+-------------------------+---------+
|  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|
+----------------+------------------+--------------+-----------------+---------+------------------------------+--------------+-----------------+-------------------------+---------+

如何做到这一点?你知道吗


Tags: ofthenamenullaugauthorsunvolume

热门问题