0

Trying to loop through all records in the IRS 990 database (json) to pull CEO compensation. Using Python 3

I've tried creating a nested loop and selecting elements in a list and dictionary, but having problems with the way the data is formatted.

import irsx
import pandas as pd
from irsx.xmlrunner import XMLRunner
xml_runner = XMLRunner()

b = ('201533089349301428', '201713189349307146')

for code in b:
   j=xml_runner.run_sked(code, 'IRS990ScheduleJ').get_result()

for i,v in enumerate(j):
for i2, v2 in v.items():
   print(v2)

Results:

IRS990ScheduleJ
{'SkdJRltdOrgOffcrTrstKyEmpl': 
   [{'object_id': '201713189349307146', 'ein': '383333202', 'PrsnNm': 'CAROLYN PICKETT-ERWAY', 'TtlTxt': 'CEO/PRESIDENT', 'BsCmpnstnFlngOrgAmt': '216799', 'CmpnstnBsdOnRltdOrgsAmt': '0', 'BnsFlngOrgnztnAmnt': '0', 'BnsRltdOrgnztnsAmt': '0', 'OthrCmpnstnFlngOrgAmt': '0', 'OthrCmpnstnRltdOrgsAmt': '0', 'DfrrdCmpnstnFlngOrgAmt': '12350', 'DfrrdCmpRltdOrgsAmt': '0', 'NntxblBnftsFlngOrgAmt': '0', 'NntxblBnftsRltdOrgsAmt': '0', 'TtlCmpnstnFlngOrgAmt': '229149', 'TtlCmpnstnRltdOrgsAmt': '0', 'CmpRprtPrr990FlngOrgAmt': '0', 'CmpRprtPrr990RltdOrgsAmt': '0'}, 
   {'object_id': '201713189349307146', 'ein': '383333202', 'PrsnNm': 'SUSAN SPRINGGATE', 'TtlTxt': 'VP, FINANCE & ADMIN.', 'BsCmpnstnFlngOrgAmt': '149792', 'CmpnstnBsdOnRltdOrgsAmt': '0', 'BnsFlngOrgnztnAmnt': '0', 'BnsRltdOrgnztnsAmt': '0', 'OthrCmpnstnFlngOrgAmt': '0', 'OthrCmpnstnRltdOrgsAmt': '0', 'DfrrdCmpnstnFlngOrgAmt': '9022', 'DfrrdCmpRltdOrgsAmt': '0', 'NntxblBnftsFlngOrgAmt': '8985', 'NntxblBnftsRltdOrgsAmt': '0', 'TtlCmpnstnFlngOrgAmt': '167799', 'TtlCmpnstnRltdOrgsAmt': '0', 'CmpRprtPrr990FlngOrgAmt': '0', 'CmpRprtPrr990RltdOrgsAmt': '0'}]}
   {'skedj_part_i': {'object_id': '201713189349307146', 'ein': '383333202', 'CmpnstnCmmttInd': 'X', 'IndpndntCnsltntInd': 'X', 'CmpnstnSrvyInd': 'X', 'BrdOrCmmttApprvlInd': 'X', 'SvrncPymntInd': '0', 'SpplmntlNnqlRtrPlnInd': '0', 'EqtyBsdCmpArrngmInd': '0', 'CmpBsdOnRvnOfFlngOrgInd': '0', 'CmpBsdOnRvRltdOrgsInd': '0', 'CmpBsdNtErnsFlngOrgInd': '0', 'CmpBsdNtErnsRltdOrgsInd': '0', 'AnyNnFxdPymntsInd': '0', 'IntlCntrctExcptnInd': '0'}}
[]

Here I have a string, dict, dict, list. But am having problems looping through the PrsnNm, and the TtlCmpnstnRltdOrgsAmt.

for i,v in enumerate(j):
for i2, v2 in v.items():
     print({i2:v2 for (i2,v2) in v2.items() if 'PrsnNm' in (v2)})

AttributeError: 'str' object has no attribute 'items'

Basically I want to skip over the string and access the dictionary.

  • 1
    This code is not properly indended so it won't run. Please [edit] and fix that. It looks like it was correct in [revision 2](https://stackoverflow.com/revisions/57135499/2). – wjandrea Jul 21 '19 at 17:50
  • Err actually, please make a [mcve]. After I read it again I realized a lot of the detail is irrelevant. As well, please ask an actual question - it helps us to understand what you're looking for. – wjandrea Jul 21 '19 at 17:56
  • 1
    Possible duplicate of [Determine the type of an object?](https://stackoverflow.com/q/2225038/4518341) - tl;dr use `isinstance(obj, str)` to check whether `obj` is of type `str`. – wjandrea Jul 21 '19 at 18:00

0 Answers0