最近總是有人問我有什么書好推薦看看,特?zé)?。但是看到那么多人問,看來挺多人有這個(gè)需求,便想了一下,如何通過數(shù)據(jù)分析找到值得看的書。通過爬取某個(gè)標(biāo)簽例如產(chǎn)品,運(yùn)營獲取對應(yīng)已經(jīng)打了標(biāo)簽的書,獲取書對應(yīng)的評分以及評價(jià)的用戶數(shù),通過獲取評分最高的30本書和評價(jià)人數(shù)最多的30本書進(jìn)行交集的處理,獲取出來的綜合指數(shù)比較高,得到的結(jié)果就是評價(jià)人數(shù)比較多且評分高的書。小編只是對產(chǎn)品,運(yùn)營,心理學(xué),python,數(shù)據(jù)分析,算法 這6個(gè)方面感興趣,分享一下這六個(gè)方面的值得讀的書,想知道其他方面的,也可以在評論下面發(fā)一下。
1. 處理過程
爬蟲主要用到python的scrapy爬蟲框架,下面是爬取數(shù)據(jù)的處理邏輯
class doubanSpider(scrapy.Spider):
name = "douban"
#要爬取的鏈接
start_urls = [
u"https://book.douban.com/tag/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90"
]
def parse(self, response):
#獲取列表的結(jié)構(gòu)
list=response.xpath('//*[@id="subject_list"]/ul/li')
for info in list:
book_name=info.xpath('div[2]/h2/a/text()').extract_first()
url=info.xpath('div[2]/h2/a/@href').extract_first()
score=info.xpath('div[2]/div[2]/span[2]/text()').extract_first()
count=info.xpath('div[2]/div[2]/span[3]/text()').extract_first()
l=JobItemLoad(JobItem())
if score is not None:
l.add_value('score', score.strip())
if count is not None:
l.add_value('count', count.strip())
l.add_value('book_name', book_name.strip())
l.add_value('url', url.strip())
yield l.load_item()
#獲取下一頁的鏈接
next_url=response.css('#subject_list > div.paginator > span.next > a::attr(href)').extract_first();
if next_url:
yield scrapy.Request('https://book.douban.com'+next_url,callback=self.parse)
爬取后的格式如下:

部分結(jié)果
對爬取后的數(shù)據(jù)進(jìn)行處理:
import pandas as pd
def fromCsv(fileName):
data = pd.read_csv(fileName,encoding = "ISO-8859-1")
return data
def toCsv(data,file_name):
data.to_csv(file_name, encoding="ISO-8859-1")
if __name__ == '__main__':
#要處理的文件的名稱
csv_names=[u'douban_analysis',u'douban_arithmetic',u'douban_psychology',u'douban_operate',u'douban_prod',u'douban_python']
for name in csv_names:
#從csv文件讀取數(shù)據(jù)
data=fromCsv(f"{name}.csv")
#分別按評分,數(shù)量進(jìn)行排序后,獲取前30個(gè)數(shù)據(jù)
count_df=data.sort_values('count', ascending=False).iloc[0:30]
score_df=data.sort_values('score', ascending=False).iloc[0:30]
#對兩個(gè)數(shù)據(jù)進(jìn)行交集的處理獲取結(jié)果
result_df=count_df[count_df["book_name"].isin(score_df['book_name'].tolist())]
toCsv(result_df.sort_values('score', ascending=False), f"{name}_result.csv")
2. 結(jié)果
2.1 產(chǎn)品
| 書名 | 評價(jià)人數(shù) | 評分 |
|---|---|---|
| 浪潮之巔 | 19783 | 9.1 |
2.2 運(yùn)營
| 書名 | 評價(jià)人數(shù) | 評分 |
|---|---|---|
| 孵化皮克斯 | 336 | 8.9 |
| 我看電商 | 1058 | 8.3 |
| SEO實(shí)戰(zhàn)密碼 | 764 | 8.3 |
| 數(shù)據(jù)化管理 | 411 | 8.3 |
| 精益數(shù)據(jù)分析 | 563 | 8.2 |
| 運(yùn)營之光 | 1939 | 8.1 |
| 你憑什么做好互聯(lián)網(wǎng) | 617 | 8.1 |
2.3 心理學(xué)
| 書名 | 評價(jià)人數(shù) | 評分 |
|---|---|---|
| 對偽心理學(xué)說不 | 3297 | 9.2 |
| 社會性動(dòng)物 | 5564 | 9.1 |
| 燈塔 | 4526 | 9.1 |
| 社會心理學(xué) | 11765 | 9 |
2.4 python
| 書名 | 評價(jià)人數(shù) | 評分 |
|---|---|---|
| 流暢的Python | 291 | 9.4 |
| Hands-On Machine Learning with Scikit-Learn and TensorFlow | 237 | 9.3 |
| Python編程:從入門到實(shí)踐 | 1000 | 9.1 |
| Python編程快速上手 | 359 | 9 |
| A Byte of Python | 1104 | 8.7 |
| Python源碼剖析 | 708 | 8.7 |
| Flask Web開發(fā):基于Python的Web應(yīng)用開發(fā)實(shí)戰(zhàn) | 478 | 8.7 |
| Python Tutorial | 193 | 8.7 |
| Python Cookbook | 341 | 8.6 |
| Dive Into Python 3 | 175 | 8.6 |
| Think Python | 218 | 8.3 |
2.5 數(shù)據(jù)分析
| 書名 | 評價(jià)人數(shù) | 評分 |
|---|---|---|
| The Elements of Statistical Learning | 509 | 9.5 |
| 概率論與數(shù)理統(tǒng)計(jì) | 569 | 9.4 |
| 行為科學(xué)統(tǒng)計(jì) | 454 | 9.4 |
2.6 算法
| 書名 | 評價(jià)人數(shù) | 評分 |
|---|---|---|
| 具體數(shù)學(xué)(英文版第2版) | 813 | 9.5 |
| 算法(第4版) | 846 | 9.4 |
| 計(jì)算機(jī)程序設(shè)計(jì)藝術(shù)(第1卷) | 449 | 9.4 |
| 算法導(dǎo)論(原書第2版) | 4788 | 9.3 |
| 數(shù)據(jù)結(jié)構(gòu) | 1235 | 7.1 |
3. 結(jié)論
其中產(chǎn)品,心理學(xué) 在評分前30,評價(jià)人數(shù)前30的交集為0,產(chǎn)品是調(diào)整為前50的數(shù)據(jù),心理學(xué)是調(diào)整為前100的數(shù)據(jù),說明偏主觀的書的綜合評分的可信度比技術(shù)類的書差一些。