试图从复杂而混乱的字典列表中提取总现金和现金等价物值。该结构的缩短版本如下。你知道吗
我试过了:地图,Dataframe.from\ u目录&;来自\u记录。尽量避免使用RE。你知道吗
我被难住了。你知道吗
[{u'Fields': [],
u'ReportDate': u'2 June 2016',
u'ReportID': u'BalanceSheet',
u'ReportName': u'Balance Sheet',
u'ReportTitles': [u'Balance Sheet',
u'Test Company',
u'As at 30 June 2016'],
u'ReportType': u'BalanceSheet',
u'Rows': [{u'Cells': [{u'Value': u''},
{u'Value': u'30 Jun 2016'},
{u'Value': u'30 Jun 2015'}],
u'RowType': u'Header'},
{u'RowType': u'Section', u'Rows': [], u'Title': u'Assets'},
{u'RowType': u'Section',
u'Rows': [{u'Cells': [{u'Attributes': [{u'Id': u'account',
u'Value': u'c0bxx922-cc31-4d53-b060-cbf23511`2533'}],
u'Value': u'Test Bank 1'},
{u'Attributes': [{u'Id': u'account',
u'Value': u'c1b4xx22-cc31-4d53-b060-cb45282533'}],
u'Value': u'5555.20'},
{u'Attributes': [{u'Id': u'account',
u'Value': u'c2b44922-cc31-4d53-b060-cbf4532582533'}],
u'Value': u'5555.20'}],
u'RowType': u'Row'},
{u'Cells': [{u'Attributes': [{u'Id': u'account',
u'Value': u'290c7c3c-a712-4ads6f-9a2f-3d5258aad5a9e'}],
u'Value': u'Test Bank 2'},
{u'Attributes': [{u'Id': u'account',
u'Value': u'490c7c32-axxxdf6f-9a2f-3db682a3ad5a9e'}],
u'Value': u'55555.20'},
{u'Attributes': [{u'Id': u'account',
u'Value': u'490xxc3c-a71-adsf6f-9a2f-3d3aad5a9e'}],
u'Value': u'55555.20'}],
u'RowType': u'Row'},
{u'Cells': [{u'Attributes': [{u'Id': u'account',
u'Value': u'c6d4da40-f0df1b0-8f7d-xx45b1405'}],
u'Value': u'Test Bank 3'},
{u'Attributes': [{u'Id': u'account',
u'Value': u'c6d4da4fg-df-41b0-8f7d-54xx345b1405'}],
u'Value': u'5555.20'},
{u'Attributes': [{u'Id': u'account',
u'Value': u'c6d4dafgss-9-41b0-8f7d-60xx5b1405'}],
u'Value': u'5555.20'}],
u'RowType': u'Row'},
{u'Cells': [{u'Value': u'Total Cash and Cash Equivalents'},
{u'Value': u'5555555.20'},
{u'Value': u'5555555.20'}],
u'RowType': u'SummaryRow'}],
u'Title': u'Cash and Cash Equivalents'},
{u'RowType': u'Section',
如果您知道数据的格式与上面的格式完全相同,并且您真的只需要这两个值,那么您可以直接访问它(假设
data
是您上面的结构):但是,无论是在写下正确的表达式时,还是在更改列表的顺序时(在您的格式中可能没有定义),这都是容易出错的。由于数据背后有一个语义结构,您可以将原始数据转换回一个易于访问的对象。您可能想更改一些细节,但这是一个很好的起点:
相关问题 更多 >
编程相关推荐