富人不僅不能多捐,老板呼籲員工捐錢給某人或投他壹票也是違法的。所以,要想籌集到幾千萬的競爭資金,唯壹的辦法就是爭取更多選民的支持,籌集壹點。所以中國,公司,大額捐款都是不合法的。
我記得中國人以前也鬧過這樣的醜聞。美國的選舉法就是為了防止少數人企圖用幾個臭錢影響美國政治。所以,作為外國人,我們不要自尋煩惱。
導入包
在[1]中:
將熊貓作為NP導入熊貓作為PD從熊貓導入系列,數據框架
方便大家操作,定義月份,候選人,政黨。
在[2]中:
months = {'JAN' : 1,' FEB' : 2,' MAR' : 3,' APR' : 4,' MAY' : 5,' JUN' : 6,' JUL' : 7,' AUG' : 8,' SEP' : 9,' OCT': 10,' NOV': 11,' DEC ':12 } of _ interest =[' Obama,Barack ','羅姆尼,Mitt ',' Santorum,Rick ',' Paul,Ron ',' Gingrich,Newt']parties = { 'Bachmann,Michelle ':
讀取文件
在[3]中:
table = PD . read _ CSV(' data/USA _ election . txt ')table . head()
c:\ jupyter \ lib \ site-packages \ IPython \ core \ interactive shell . py:2785:dtype warning:列(6)具有混合類型。請在導入時指定dtype選項,或者設置low_memory=False。交互性=交互性,編譯器=編譯器,結果=結果)
Out[3]:
cmte _ idcand _ idcand _ nmcontbr _ nmcontbr _ citycontbr _ stcontbr _ zipcontbr _ employeercontbr _ occupationcontb _ receipt _ amtcontb _ receipt _ dt receipt _ desc memo _ CD memo _ text form _ TP file _ num
0c 00410118p 20002978 Bachmann,MichelleHARVEY,WILLIAMMOBILEAL 3.6601e 08 retired retired 250.0 JUN-111nannannans 17A 736166
1c 00410118p 20002978 Bachmann,MichelleHARVEY,WILLIAMMOBILEAL 3.6601e 08退休退休50.0 JUN-111nannannans 17A 736166
2c 00410118p 20002978 Bachmann,MichelleSMITH,LANIERLANETTAL 3.68633e信息請求信息請求250.0 05-7-111nannannans 17A 749073
3c 00410118p 20002978 Bachmann,MichelleBLEVINS,DARONDAPIGGOTTAR 7.24548 e 08 none retired 250.0 01-AUG-111 nannan nans 17A 749073
4c 00410118p 20002978 Bachmann,MichelleWARDENBURG,Harold hot SPRINGS NATIONAR 7.19016e 08 none retired 300.0 20-JUN-1111nannannans 17A 736166
在[8]中:
#使用映射函數字典創建壹個新的party表列表['party'] = table ['Cand _ nm']。地圖(各方)表。頭部()。
Out[8]:
cmte _ idcand _ idcand _ nmcontbr _ nmcontbr _ citycontbr _ stcontbr _ zipcontbr _ employeercontbr _ occupationcontb _ receipt _ amtcontb _ receipt _ dt receipt _ descmo _ CD memo _ text form _ TP file _ num party
0c 00410118p 20002978 Bachmann,MichelleHARVEY,WILLIAMMOBILEAL 3.66018 retired retired 250.0 20-JUN-111nannannans 17A 736166共和黨
1c 00410118p 20002978 Bachmann,MichelleHARVEY,WILLIAMMOBILEAL 3.6601e 08退休50.0 JUN-111nannannans 17A 736166共和
2c 00410118p 20002978 Bachmann,MichelleSMITH,LANIERLANETTAL 3.68633e信息請求信息請求250.0 05-07-111nannannans 17A 749073 Republican
3c 00410118p 20002978 Bachmann,MichelleBLEVINS,DARONDAPIGGOTTAR 7.24548 e 08 none retired 250.0 01-AUG-111 nannan nans 17A 749073共和國
4c 00410118p 20002978 Bachmann,MichelleWARDENBURG,Harold hot SPRINGS NATIONAR 7.19016e 08 none retired 300.0 20-JUN-1111nannannans 17A 736166共和黨
在[10]:
#party表['party']列中的元素是什麽。唯壹()
Out[10]:
數組(['共和黨','民主黨','改革','自由主義'],dtype=object)
在[ ]:
#使用value_counts()函數計算party列中每個元素的出現次數。value_counts()在序列中,沒有參數。返回包含每個元素出現次數的序列。
在[11]:
表['party']。值計數()
Out[11]:
民主黨292400共和黨237575改革5364自由黨702名稱:政黨,數據類型:int64
在[12]:
#使用groupby()函數檢查每個政黨收到的政治獻金總額,contb _ receipt _ AMT表。分組依據(by = ' party ')[' contb _ receipt _ AMT ']。sum()。
Out[12]:
民主黨8.105758 e 07自由黨4.132769 e 05改革黨3.390338e共和黨1.192255 e 08 name:contb _ receipt _ AMT,dtype: float64
在[13]:
#查看各黨每天收到的政治獻金總額-contb_receipt_amt。使用groupby([多個分組參數])表。groupby (by = ['party ',' contb _ receipt _ dt '])[' contb _ receipt _ AMT ']。sum()。
Out[13]:
party contb _ receipt _ dt Democrat 01-AUG-11 65281.00 01-DEC-11 651532.82 01-JAN-12 58098.80 065433...共和黨29-8-11 941769.23 29-12-11 428501.42 29-1-11 750.00 29-1-654 38+02 75220.02 29-7-65438
在[14]:
def transform _ date(d):day,month,year = d . split('-')month = months[month]return " 20 " year '-' str(month)'-' day
在[17]:
#將表格中的日期格式轉換為“yyyy-mm-dd”。日期格式,由函數加映射表['contb _ receipt _ dt'] =表['contb _ receipt _ dt']。應用(trasform _ date)。
在[18]:
table.head()
Out[18]:
cmte _ idcand _ idcand _ nmcontbr _ nmcontbr _ citycontbr _ stcontbr _ zipcontbr _ employeercontbr _ occupationcontb _ receipt _ amtcontb _ receipt _ dt receipt _ descmo _ CD memo _ text form _ TP file _ num party
0c 00410118p 20002978 Bachmann,MichelleHARVEY,WILLIAMMOBILEAL 3.66018 retired retired 250.0 2011-6-20 nannannans 17A 736166共和
1c 00410118p 20002978巴赫曼、米歇爾·哈維、威廉·莫比利爾3.6601e 08退休50.0 2011-6-23南南南17A 736166共和
2c 00410118p 20002978 Bachmann,MichelleSMITH,LANIERLANETTAL 3.68633e信息請求信息請求250.0 2011-7-05 nannannan nans 17A 749073 Republican
3c 00410118p 20002978 Bachmann,MichelleBLEVINS,DARONDAPIGGOTTAR 7.24548 e 08 none retired 250.0 2011-8-01 nannannans 17A 749073 Republican
4c 00410118p 20002978 Bachmann,MichelleWARDENBURG,Harold hot SPRINGS NATIONAR 7.19016e 08 none retired 300.0 2011-6-20 nannannan nans 17A 736166共和黨
在[19]:
#查誰退伍軍人(捐助職業)主要支持:查誰退伍軍人捐款最多表['contbr _ occupation'] = = '傷殘退伍軍人'
Out[19]:
0假1假2假3假4假5假6假7假8假9假10假12假13假14假15假16假17假18假19假20假2...536011假536012假536013假536014假536016假536017假536018假536019假5366438
In [21]:
old _ bing _ df = table . loc[table[' cont br _ occupation ']= '殘疾老兵']
在[22]中:
old _ bing _ df . group by(by = ' cand _ nm ')[' contb _ receipt _ AMT ']。總和()
Out[22]:
cand_nmCain,Herman 300.00Obama,Barack 4205.00Paul,Ron 2425.49Santorum,Rick 250.00 name:contb _ receipt _ AMT,dtype: float64
在[23]中:
表['contb_receipt_amt']。最大()
Out[23]:
1944042.43
在[24]中:
#找出候選人捐款金額最大的捐款人的職業和捐款金額。通過查詢(“查詢條件”)表找到捐贈人的職業。查詢(' contb _ receipt _ AMT = = 1944042.43 ')。
Out[24]:
cmte _ idcand _ idcand _ nmcontbr _ nmcontbr _ citycontbr _ stcontbr _ zipcontbr _ employeercontbr _ occupationcontb _ receipt _ amtcontb _ receipt _ dt receipt _ descmo _ CD memo _ text form _ TP file _ num party
176127 c 00431445 p 80003338奧巴馬、巴拉克奧巴馬勝利基金2012-unitemized chicagoil 60680 nannan 1944042.43 2011-12-31 nannx * sa 65438
來源:/content-1-497751 . html。