方便大家操作,将月份和参选人以及所在政党进行定义:

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', 'Romney, Mitt', 'Santorum, Rick','Paul, Ron', 'Gingrich, Newt']

parties = {
    'Bachmann, Michelle': 'Republican',
    'Romney, Mitt': 'Republican',
    'Obama, Barack': 'Democrat',
    "Roemer, Charles E. 'Buddy' III": 'Reform',
    'Pawlenty, Timothy': 'Republican',
    'Johnson, Gary Earl': 'Libertarian',
    'Paul, Ron': 'Republican',
    'Santorum, Rick': 'Republican',
    'Cain, Herman': 'Republican',
    'Gingrich, Newt': 'Republican',
    'McCotter, Thaddeus G': 'Republican',
    'Huntsman, Jon': 'Republican',
    'Perry, Rick': 'Republican'
}

完成下列需求: 

1.读取文件usa_election.txt
2.查看文件样式及基本信息
3.【知识点】使用map函数+字典,新建一列各个候选人所在党派party
4.使用np.unique()函数查看colums:party这一列中有哪些元素
5.使用value_counts()函数,统计party列中各个元素出现次数,value_counts()是Series中的,无参,返回一个带有每个元素出现次数的Series
6.【知识点】使用groupby()函数,查看各个党派收到的政治献金总数contb_receipt_amt
7.查看具体每天各个党派收到的政治献金总数contb_receipt_amt。使用groupby([多个分组参数])
8.将表中日期格式转换为'yyyy-mm-dd'。日期格式,通过函数加map方式进行转换
9.查看老兵(捐献者职业)DISABLED VETERAN主要支持谁 :查看老兵们捐赠给谁的钱最多
10.找出各个候选人的捐赠者中,捐赠金额最大的人的职业以及捐赠额,通过query("查询条件来查找捐献人职业")
需求列表

相关文章:

  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
  • 2021-10-25
  • 2022-02-08
猜你喜欢
  • 2021-09-26
  • 2022-02-08
  • 2022-12-23
  • 2022-02-14
  • 2022-12-23
  • 2021-11-17
  • 2021-06-08
相关资源
相似解决方案