OpenSecrets_Senators_Industries.OpenSecrets_Senators_Industries
Python package that allows users to view information about their senators and the industries that fund them.
This module uses the OpenSecrets and ProPublica APIs and scraps the OpenSecrets website to return information about the top 20 industries that fund the US Congress and the senators who have received the most funding from these industries.
Module Contents
Classes
All functions that require the ProPublica API Key. |
|
All functions that require the OpenSecrets API Key. |
Functions
|
Extracts the Top 20 Industries that have spent the most on Federal Lobbying from |
- OpenSecrets_Senators_Industries.OpenSecrets_Senators_Industries.top_20_industries_ids(year='a')
Extracts the Top 20 Industries that have spent the most on Federal Lobbying from https://www.opensecrets.org/federal-lobbying/industries.
- Parameters
year (str, optional) – Specific year (1998 - 2021) for which to retrieve the data for (the default is ‘a’ which would return the total amount of money spent on Federal Lobbying across all years from 1998 - 2021).
- Returns
Dataframe containing the Top 20 Industries that have spent the most on Federal Lobbying, the amount of money they have each spent, and their unique Industry IDs.
- Return type
pandas.DataFrame
Examples
>>> top_20_industries_ids() [ Industry Total IDs 0 Pharmaceuticals/Health Products $4,990,257,367 H04 1 Insurance $3,210,878,113 F09 2 Electronics Mfg & Equip $2,795,736,767 B12 3 Electric Utilities $2,757,808,440 E08 4 Business Associations $2,623,983,096 N00 5 Oil & Gas $2,489,418,498 E01 6 Hospitals/Nursing Homes $2,025,651,797 H02 7 Misc Manufacturing & Distributing $2,008,839,171 N15 8 Education $1,902,258,320 W04 9 Securities & Investment $1,897,760,970 F07 10 Civil Servants/Public Officials $1,887,599,161 W03 11 Telecom Services $1,883,769,733 B09 12 Real Estate $1,874,450,800 F10 13 Air Transport $1,730,349,996 M01 14 Health Professionals $1,712,045,500 H01 15 Health Services/HMOs $1,405,134,830 H03 16 Automotive $1,322,462,732 M02 17 TV/Movies/Music $1,301,018,584 B02 18 Misc Issues $1,247,693,549 Q10 19 Defense Aerospace $1,232,991,613 D01 ]
- class OpenSecrets_Senators_Industries.OpenSecrets_Senators_Industries.ProPublicaAPIKey(propublica_api_key)
All functions that require the ProPublica API Key.
- propublica_api_key
ProPublica API Key to use ProPublica’s Congress API. The API Key can be requested from https://www.propublica.org/datastore/api/propublica-congress-api.
- Type
str
- senate_members(self, congress_sitting=117)
Uses the ProPublica API to extract a list of Senators.
- Parameters
congress_sitting (int, optional) – Allows the user to specify senators from which sitting of Congress (80-117) they would like information about (the default is 117, which would return all the senators in the 117th Congress).
- Returns
Pandas DataFrame containing the names, state and CRP IDs of all senators in a particular sitting of Congress.
- Return type
pandas.DataFrame
Examples
>>> ProPublica = ProPublicaAPIKey('insert ProPublica API Key here') >>> ProPublica.senate_members() [ first_name middle_name last_name state crp_id 0 Tammy None Baldwin WI N00004367 1 John None Barrasso WY N00006236 2 Michael None Bennet CO N00030608 3 Marsha None Blackburn TN N00003105 4 Richard None Blumenthal CT N00031685 ... ... ... ... ... ... 97 Elizabeth None Warren MA N00033492 98 Sheldon None Whitehouse RI N00027533 99 Roger None Wicker MS N00003280 100 Ron None Wyden OR N00007724 101 Todd None Young IN N00030670 102 rows × 5 columns ]
- class OpenSecrets_Senators_Industries.OpenSecrets_Senators_Industries.OpenSecretsAPIKey(opensecrets_api_key)
All functions that require the OpenSecrets API Key.
- opensecrets_api_key
OpenSecrets API Key to use ProPublica’s Congress API. The API Key can be requested from https://www.opensecrets.org/api/admin/index.php?function=signup.
- Type
str
- top_senators_each_industry(self, propublica_api_key, industry_id='H04', **kwargs)
Uses the OpenSecretsAPI and ProPublica API to provide the user with the senators who have received the most amount of funding from a particular industry.
As the function makes as many calls as there are senators in a particular sitting of Congress, it may take a while to return the necessary results.
- Parameters
propublica_api_key (class ProPublicaAPIKey) – The user’s ProPublica API Key. See documentation on ProPublicaAPIKey.
industry_id (str, optional) – Unique industry_id. Full list of industry IDs can be found at www.opensecrets.org/downloads/crp/CRP_IDs.xls. The user can also call top_20_industries_ids() to retrieve industry_ids. See documentation on top_20_industries_ids() (the default is ‘H04’, corresponding to Pharmaceuticals/Health Products industry).
**kwargs (str, optional) – Extra arguments to ‘propublica_api_key.senate_members’. See documentation on propublica_api_key.senate_members for possible arguments.
- Returns
Pandas DataFrame with Senators ranked according to who has received the most amount of funding from a particular industry.
- Return type
pandas.DataFrame
Examples
>>> OpenSecrets = OpenSecretsAPIKey('insert OpenSecrets API Key here') >>> ProPublica = ProPublicaAPIKey('insert ProPublica API Key here') >>> OpenSecrets.top_senators_each_industry(ProPublica, industry_id = 'F09', congress_sitting = 116) [ cand_name cid cycle industry last_updated party state total 0 Casey, Bob N00027503 2018 Insurance 06/10/19 D Pennsylvania 357820.0 1 Scott, Rick N00043290 2018 Insurance 06/10/19 R Florida 328912.0 2 Brown, Sherrod N00003535 2018 Insurance 06/10/19 D Ohio 316800.0 3 McSally, Martha N00033982 2018 Insurance 06/10/19 R Arizona 294825.0 4 Stabenow, Debbie N00004118 2018 Insurance 06/10/19 D Michigan 292400.0 ... ... ... ... ... ... ... ... ... 95 Boozman, John N00013873 2018 Insurance 06/10/19 R Arkansas 3450.0 96 Lee, Mike N00031696 2018 Insurance 06/10/19 R Utah 3250.0 97 Udall, Tom N00006561 2018 Insurance 06/10/19 D New Mexico 1058.0 98 Leahy, Patrick N00009918 2018 Insurance 06/10/19 D Vermont 1015.0 99 Shelby, Richard C N00009920 2018 Insurance 06/10/19 R Alabama -5000.0 100 rows × 8 columns ]
See also