看晋江总分榜积分与字数的关系

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 

import urllib.request
import urllib.error
import re
import threading
from lxml import etree
import time
import pandas as pd
import sys
import numpy as np   #numpy计算包
import matplotlib.pyplot as plt
import chardet
import matplotlib
matplotlib.rcParams['figure.figsize'] = (10.0, 5.0)
import matplotlib.pylab as pyl#折线图、散点图plot,直方图hist
import requests
from requests import get


headers = {'Accept':'*/*',
            'Accept-Encoding':   'gzip, deflate',
            'Accept-Language':    'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
            'Connection':   'keep-alive',
            'Cookie':    'cna=um0tE7tQllkCAXE21MrqNDM2',
            'DNT':    1,
            'Host':    'afp.csbew.com',
            'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:57.0) Gecko/20100101 Firefox/57.0'}

url="http://www.jjwxc.net/topten.php?orderstr=7"
response = requests.get(url,params = headers)
response.encoding = "gb2312"#原网页为gb2312编码
html = response.text


html = etree.HTML(html)
bookname = html.xpath('//a[@class="tooltip"]/text()')
writenum = html.xpath('//td[@align="right"]/text()')
score = html.xpath('//tbody/tr/td[@bgcolor="#eefaee"]/text()')

df=pd.DataFrame(columns=["书名","字数","积分"])

for i in range(0,200):#共200条数据
    book_name=bookname[i]
    write_num=writenum[i].strip()#去掉空格占位符
    score_num = score[i]
    s = pd.Series({'书名':book_name,'字数':write_num, '积分':score_num})
    df = df.append(s, ignore_index=True)#若不指定ignore_index参数,则会把添加的数据的index保留下来,若ignore_index=Ture则会对所有的行重新自动建立索引。
df.to_csv("D://jj2.csv",index=False,encoding="utf_8_sig")


data=pd.read_csv("D://jj2.csv")
data2=data.T
x1=data2.values[1]
y1=data2.values[2]
pyl.xlabel("write_num")#横轴
pyl.ylabel("score_num")#纵轴,不显示
pyl.ylim(800000000,6000000000)#不显示
pyl.ylim(0,100)
pyl.plot(x1,y1,'or')
pyl.show()


 

其实,三列数据可以直接从网站copy得到,此次只为做训练。下图纵轴不显示名称和坐标,待解决。

jj

此图用spss做出,因纵坐标的不一致导致图形不同,经过分析,存在部分点为异常点,标准残差不在【-3,3】之间,可找出这些分析原因。

jj-spss

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值