python pandas爬取网页成绩表格,计算各个类别学分

本文介绍了如何使用Python的pandas库从网页抓取成绩表格,并详细展示了计算各个类别学分的过程,包括编写程序代码及运行的部分结果。
摘要由CSDN通过智能技术生成

一、以下是个人成绩表格


二、下面是我的程序:

# -- coding: utf-8 --
import pandas as pd
import csv

def credit_points_sum(df,title):
    df.to_csv('E:\\scores_'+title+'.csv',  encoding='utf_8_sig')  # index=False,header=False
    sum=0
    for i in range(df.shape[0]):
        sum+=float(df.iloc[i][4])
    print(title+':'+str(sum))


url='E://scores.html'
tb=pd.read_html(url)[1]
tb=tb[1:70]
print(tb.iloc[0][6])
tb[4].astype(float)
print(tb)

# 总学分
credit_points_sum(tb, u'总学分')

# 专选
tb_zhuanXuan=tb[tb[6]=='专选']
credit_points_sum(tb_zhuanXuan,'专选')


# 必修
tb_biXiu=tb[tb[6]=='必修']
credit_points_sum(tb_biXiu,'必修')


# 素质
tb_suZhi=tb[tb[6]=='素质']
credit_points_sum(tb_suZhi,'素质')

# 专选非限
tb_suZhi=tb[tb[6]=='专选(非限)']
credit_points_sum(tb_suZhi,'专选(非限)')


三、下面是运行的部分结果


四、下面是个人下载下来的静态html


<html>
<title>学生个人总成绩查询</title>
<head>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<LINK href="/include/style.css" type=text/css rel=stylesheet>
</head>
<body >

<center>
<table BORDER="0" cellspacing="0"   height="80%">
<tr>
<td>
</td></tr>
<tr>
<td align="center">


<p><B><font size="3">重庆大学学生成绩单</font></B></p>
                                                                                   

<p><B>学号:</B>20161590  <B>姓名:</B>谭植尹  <B>专业:</B>软件工程 <B>GPA:</B>3.22</B> </p>
<table BORDER="1" cellspacing="0" cellpadding="2" bordercolorlight="#000000"
bordercolordark="#FFFFFF" bordercolor="#FFFFFF" width="877">
  <tr>
    <td width="32"><b>序号</b></td>
    <td width="84"><b>课程编码</b></td>
    <td width="210"><b>课程名称</b></td>
    <td width="43"><b>成绩</b></td>
    <td width="43"><b>学分</b></td>
    <td width="53"><b>选修</b></td>
    <td width="52"><b>类别</b></td>
    <td width="60"><b>教师</b></td>
    <td width="54"><b>考别</b></td>
    <td width="38"><b>备注</b></td>
    <td width="140"><b>时间</b></td>
  </tr>

  <tr>

    <td align="center" VALIGN="center" width="32" height="23"> 
      1
    </td>
    <td align="center"  VALIGN="center" width="84" height="23"> 
      SE31029
    </td>
    <td VALIGN="center" width="210" height="23"> 
      .NET框架及C#程序设计
    </td>
    <td  align="center" VALIGN="center" width="43" height="23">
	76
    </td>
    <td  align="center" VALIGN="center" width="43" height="23"> 
      2
    </td>
    <td  align="center" VALIGN="center" width="53" height="23"> 
      
	  正常
      
    </td>
    <td  align="center" VALIGN="center" width="52" height="23"> 
      
      专选 
      
    </td>
    <td align="center"  VALIGN="center" width="60" height="23"> 
       祝伟华
    </td>
    <td align="center"  VALIGN="center" width="54" height="23"> 
	正考
    </td>
    <td align="center"  VALIGN="center" width="38" height="23"> 
	  正
    </td>
    <td align="center"  VALIGN="center" width="140" height="23"> 
	  2018-12-1
    </td>
  </tr>

  <tr>

    <td align="center" VALIGN="center" width="32" height="23"> 
      2
    </td>
    <td align="center"  VALIGN="center" width="84" height="23"> 
      SE31209
    </td>
    <td VALIGN="center" width="210" height="23"> 
      DirectX图形程序设计
    </td>
    <td  align="center" VALIGN="center" width="43" height="23">
	81
    </td>
    <td  align="center" VALIGN="center" width="43" height="23"> 
      2
    </td>
    <td  align="center" VALIGN="center" width="53" height="23"> 
      
	  正常
      
    </td>
    <td  align="center" VALIGN="center" width="52" height="23"> 
      
      专选 
      
    </td>
    <td align="center"  VALIGN="center" width="60" height="23"> 
       曾骏
    </td>
    <td align="center"  VALIGN="center" width="54" height="23"> 
	正考
    </td>
    <td align="center"  VALIGN="center" width="38" height="23"> 
	  正
    </td>
    <td align="center"  VALIGN="center" width="140" height="23"> 
	  2019-1-10
    </td>
  </tr>

  <tr>

    <td align="center" VALIGN="center" width="32" height="23"> 
      3
    </td>
    <td align="center"  VALIGN="center" width="84" height="23"> 
      SE21023
    </td>
    <td VALIGN="center" width="210" height="23"> 
      Java EE程序设计
    </td>
    <td  align="center" VALIGN="center" width="43" height="23">
	82
    </td>
    <td  align="center" VALIGN="center" width="43" height="23"> 
      2
    </td>
    <td  align="center" VALIGN="center" width="53" height="23"> 
      
	  正常
      
    </td>
    <td  align="center" VALIGN="center" width="52" height="23"> 
      
      专选 
      
    </td>
    <td align="center"  VALIGN="center" width="60" height="23"> 
       黄晟
    </td>
    <td align="center"  VALIGN="center" width="54" height="23"> 
	正考
    </td>
    <td align="center"  VALIGN="center" width="38" height="23"> 
	  正
    </td>
    <td align="center"  VALIGN="center" width="140" height="23"> 
	  2018-7-16
    </td>
  </tr>

  <tr>

    <td align="center" VALIGN="center" width="32" height="23"> 
      4
    </td>
    <td align="center"  VALIGN="center" width="84" height="23"> 
      SE31107
    </td>
    <td VALIGN="center" width="210" height="23"> 
      Web开发技术
    </td>
    <td  align="center" VALIGN="center" width="43" height="23">
	95
    </td>
    <td  align="center" VALIGN="center" width="43" height="23"> 
      2
    </td>
    <td  align="center" VALIGN="center" width="53" height="23"> 
      
	  正常
      
    </td>
    <td  align="center" VALIGN="center" width="52" height="23"> 
      
      必修 
      
    </td>
    <td align="center"  VALIGN="center" width="60" height="23"> 
       王成良
    </td>
    <td align="center"  VALIGN="center" width="54" height="23"> 
	正考
    </td>
    <td align="center"  VALIGN="center" width="38" height="23"> 
	  正
    </td>
    <td align="center"  VALIGN="center" width="140" height="23"> 
	  2019-1-18
    </td>
  </tr>

  <tr>

    <td align="center" VALIGN="center" width="32" height="23"> 
      5
    </td>
    <td align="center"  VALIGN="center" width="84" height="23"> 
      SE21021
    </td>
    <td VALIGN="center" width="210" height="23"> 
      操作系统原理
    </td>
    <td  align="center" VALIGN="center" width="43" height="23">
	96
    </td>
    <td  align="center" VALIGN="center" width="43" height="23"> 
      3
    </td>
    <td  align="center" VALIGN="center" width="53" height="23"> 
      
	  正常
      
    </td>
    <td  align="center" VALIGN="center" width="52" height="23"> 
      
      必修 
      
    </td>
    <td align="center"  VALIGN="center" width="60" height="23"> 
       洪明坚
    </td>
    <td align="center"  VALIGN="center" width="54" height="23"> 
	正考
    </td>
    <td align="center"  VALIGN="center" width="38" height="23"> 
	  正
    </td>
    <td align="center"  VALIGN="center" width="140" height="23"> 
	  2018-7-15
    </td>
  </tr>

  <tr>

    <td align="center" VALIGN="center" width="32" height="23"> 
      6
    </td>
    <td align="center"  VALIGN="center" width="84" height="23"> 
      SE11005
    </td>
    <td VALIGN="center" width="210" height="23"> 
      程序设计基础
    </td>
    <td  align="center" VALIGN="center" width="43" height="23">
	84
    </td>
    <td  align="center" VALIGN="center" width="43" height="23"> 
      4
    </td>
    <td  align="center" VALIGN="center" width="53" height="23"> 
      
	  正常
      
    </td>
    <td  align="center" VALIGN="center" width="52" height="23"> 
      
      必修 
      
    </td>
    <td align="center"  VALIGN="center" width="60" height="23"> 
       黄晟
    </td>
    <td align="center"  VALIGN="center" width="54" height="23"> 
	正考
    </td>
    <td align="center"  VALIGN="center" width="38" height="23"> 
	  正
    </td>
    <td align="center"  VALIGN="center" width="140" height="23"> 
	  2017-1-17
    </td>
  </tr>

  <tr>

    <td align="center" VALIGN="center" width="32" height="23"> 
      7
    </td>
    <td align="center"  VALIGN="center" width="84" height="23"> 
      SE24061
    </td>
    <td VALIGN="center" width="210" height="23"> 
      程序设计实训
    </td>
    <td  align="center" VALIGN="center" width="43" height="23">
	80
    </td>
    <td  align="center" VALIGN="center" width="43" height="23"> 
      3
    </td>
    <td  align="center" VALIGN="center" width="53" height="23"> 
      
	  正常
      
    </td>
    <td  align="center" VALIGN="center" width="52" height="23"> 
      
      必修 
      
    </td>
    <td align="center"  VALIGN="center" width="60" height="23"> 
       雷跃明
    </td>
    <td align="center"  VALIGN="center" width="54" height="23"> 
	正考
    </td>
    <td align="center"  VALIGN="center" width="38" height="23"> 
	  正
    </td>
    <td align="center"  VALIGN="center" width="140" height="23"> 
	  2017-9-11
    </td>
  </tr>

  <tr>

    <td align="center" VALIGN="center" width="32" height="23"> 
      8
    </td>
    <td align="center"  VALIGN="center" width="84" height="23"> 
      HG00046
    </td>
    <td VALIGN="center" width="210" height="23"> 
      大学国文(上)
    </td>
    <td  align="center" VALIGN="center" width="43" height="23">
	82
    </td>
    <td  align="center" VALIGN="center" width="43" height="23"> 
      2
    </td>
    <td  align="center" VALIGN="center" width="53" height="23"> 
      
	  正常
      
    </td>
    <td  align="center" VALIGN="center" width="52" height="23"> 
      
      素质 
      
    </td>
    <td align="center"  VALIGN="center" width="60" height="23"> 
       彭磊
    </td>
    <td align="center"  VALIGN="center" width="54" height="23"> 
	正考
    </td>
    <td align="center"  VALIGN="center" width="38" height="23"> 
	  正
    </td>
    <td align="center"  VALIGN="center" width="140" height="23"> 
	  2016-12-30
    </td>
  </tr>

  <tr>

    <td align="center" VALIGN="center" width="32" height="23"> 
      9
    </td>
    <td align="center"  VALIGN="center" width="84" height="23"> 
      HG00047
    </td>
    <td VALIGN="center" width="210" height="23"> 
      大学国文(下)
    </td>
    <td  align="center" VALIGN="center" width="43" height="23">
	81
    </td>
    <td  align="center" VALIGN="center" width="43" height="23"> 
      2
    </td>
    <td  align="center" VALIGN="center" width="53" height="23"> 
      
	  正常
      
    </td>
    <td  align="center" VALIGN="center" width="52" height="23"> 
      
      素质 
      
    </td>
    <td align="center"  VALIGN="center" width="60" height="23"> 
       刘扬
    </td>
    <td align="center"  VALIGN="center" width="54" height="23"> 
	正考
    </td>
    <td align="center"  VALIGN="center" width="38" height="23"> 
	  正
    </td>
    <td align="center"  VALIGN="center" width="140" height="23"> 
	  2017-6-20
    </td>
  </tr>

  <tr>

    <td align="center" VALIGN="center" width="32" height="23"> 
      10
    </td>
    <td align="center"  VALIGN="center" width="84" height="23"> 
      PYS10013
    </td>
    <td VALIGN="center" width="210" height="23"> 
      大学物理Ⅱ-1
    </td>
    <td  align="center" VALIGN="center" width="43" height="23">
	76
    </td>
    <td  align="center" VALIGN="center" width="43" height="23"> 
      3.5
    </td>
    <td  align="center" VALIGN="center" width="53" height="23"> 
      
	  正常
      
    </td>
    <td  align="center" VALIGN="center" width="52" height="23"> 
      
      必修 
      
    </td>
    <td align="center"  VALIGN="center" width="60" height="23"> 
       苏荀
    </td>
    <td align="center"  VALIGN="center" width="54" height="23"> 
	正考
    </td>
    <td align="center"  VALIGN="center" width="38" height="23"> 
	  正
    </td>
    <td align="center"  VALIGN="center" width="140" height="23"> 
	  2017-7-7
    </td>
  </tr>

  <tr>

    <td align="center" VALIGN="center" width="32" height="23"> 
      11
    </td>
    <td align="center"  VALIGN="center" width="84" height="23"> 
      PYS12010
    </td>
    <td VALIGN="center" width="210" height="23"> 
      大学物理实验
    </td>
    <td  align="center" VALIGN="center" width="43" height="23">
	77
    </td>
    <td  align="center" VALIGN="center" width="43" height="23"> 
      1.5
    </td>
    <td  align="center" VALIGN="center" width="53" height="23"> 
      
	  正常
      
    </td>
    <td  align="center" VALIGN="center" width="52" height="23"> 
      
      必修 
      
    </td>
    <td align="center"  VALIGN="center" width="60" height="23"> 
       余沛
    </td>
    <td align="center"  VALIGN="center" width="54" height="23"> 
	正考
    </td>
    <td align="center"  VALIGN="center" width="38" height="23"> 
	  正
    </td>
    <td align="center"  VALIGN="center" width="140" height="23"> 
	  2017-7-7
    </td>
  </tr>

  <tr>

    <td align="center" VALIGN="center" width="32" height="23"> 
      12
    </td>
    <td align="center"  VALIGN="center" width="84" height="23"> 
      5200080
    </td>
    <td VALIGN="center" width="210" height="23"> 
      大学英语(国家四级)
    </td>
    <td  align="center" VALIGN="center" width="43" height="23">
	453
    </td>
    <td  align="center" VALIGN="center" width="43" height="23"> 
      1
    </td>
    <td  align="center" VALIGN="center" width="53" height="23"> 
      
	  正常
      
    </td>
    <td  align="center" VALIGN="center" width="52" height="23"> 
      
      任选 
      
    </td>
    <td align="center"  VALIGN="center" width="60" height="23"> 
       国家四级
    </td>
    <td align="center"  VALIGN="center" width="54" height="23"> 
	正考
    </td>
    <td align="center"  VALIGN="center" width="38" height="23"> 
	  正
    </td>
    <td align="center"  VALIGN="center" width="140" height="23"> 
	  2017-9-12
    </td>
  </tr>

  <tr>

    <td align="center" VALIG
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值