我从一个CSV文件创建了一个嵌套字典,它映射了数据的结构。我现在需要重新排列表格格式的数据,(并不一定需要在一个表,但它只是需要布置的方式,是可以理解的基于嵌套字典创建表格
嵌套的字典是这样的:
{ 'CA': { 'Bay Area ': [ ('warm? ', 'yes\n'),
('East/West Coast? ', 'West \n')],
'SoCal ': [ ('north or south? ', 'south \n'),
('warm ', 'yes \n')]},
'MA': { 'Boston ': [ ('East/West Coast? ', 'East \n'),
('like it there? ', 'yes\n')],
'Pioneer Valley ': [ ('East/West Coast? ', 'East \n'),
('city? ', 'no\n'),
('college town? ', 'yes\n')]},
'NY': { 'Brooklyn ': [ ('East/West Coast? ', 'East \n'),
('been there? ', 'yes\n'),
('Been to coney island? ', 'yes\n')],
'Manhattan ': [ ('East/West Coast? ', 'East \n'),
('been there? ', 'yes\n')],
'Queens ': [ ('East/West Coast? ', 'East \n'),
('been there? ', 'yes\n')],
'Staten Island ': [('is island? ', 'yes\n')]}}
的信息需要被格式化成这样:
如何以这种格式在蟒纹出该信息或者,如果我使用一个模块,哪些模块做我用什么在该模块中起作用我应该使用吗?
您可以使用Pandas或模块表格。看看这里:https://stackoverflow.com/questions/9535954/printing-lists-as-tabular-data。无论如何,你应该调整该方法的字典。 – CunivL