最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于python爬蟲(chóng)數(shù)據(jù)處理(詳解)

 更新時(shí)間:2017年06月10日 09:26:13   投稿:jingxian  
下面小編就為大家?guī)?lái)一篇基于python爬蟲(chóng)數(shù)據(jù)處理(詳解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

一、首先理解下面幾個(gè)函數(shù)

設(shè)置變量 length()函數(shù) char_length() replace() 函數(shù) max() 函數(shù)

1.1、設(shè)置變量 set @變量名=值

set @address='中國(guó)-山東省-聊城市-莘縣';
select @address

1.2 、length()函數(shù) char_length()函數(shù)區(qū)別

select length('a')
,char_length('a')
,length('中')
,char_length('中')

1.3、 replace() 函數(shù) 和length()函數(shù)組合

set @address='中國(guó)-山東省-聊城市-莘縣';
select @address
,replace(@address,'-','') as address_1
,length(@address) as len_add1
,length(replace(@address,'-','')) as len_add2
,length(@address)-length(replace(@address,'-','')) as _count

etl清洗字段時(shí)候有明顯分割符的如何確定新的數(shù)據(jù)表增加幾個(gè)分割出的字段

計(jì)算出com_industry中最多有幾個(gè) - 符 以便確定增加幾個(gè)字段 最大值+1 為可以拆分成的字段數(shù) 此表為3 因此可以拆分出4個(gè)行業(yè)字段 也就是4個(gè)行業(yè)等級(jí)

select max(length(com_industry)-length(replace(com_industry,'-',''))) as _max_count
from etl1_socom_data

1.4、設(shè)置變量 substring_index()字符串截取函數(shù)用法

set @address='中國(guó)-山東省-聊城市-莘縣';
select 
substring_index(@address,'-',1) as china,
substring_index(substring_index(@address,'-',2),'-',-1) as province,
substring_index(substring_index(@address,'-',3),'-',-1) as city,
substring_index(@address,'-',-1) as district

1.5、條件判斷函數(shù) case when

case when then when then else 值 end as 字段名

select case when 89>101 then '大于' else '小于' end as betl1_socom_data

二、kettle轉(zhuǎn)換etl1清洗

首先建表 步驟在視頻里

字段索引 沒(méi)有提 索引算法建議用BTREE算法增強(qiáng)查詢效率

2.1.kettle文件名:trans_etl1_socom_data

2.2.包括控件:表輸入>>>表輸出

2.3.數(shù)據(jù)流方向:s_socom_data>>>>etl1_socom_data

kettle轉(zhuǎn)換1截圖

2.4、表輸入2.4、SQL腳本 初步清洗com_district和com_industry字段

select a.*,
case when com_district like '%業(yè)' or com_district like '%織' or com_district like '%育' then null else com_district end as com_district1
,case when com_district like '%業(yè)' or com_district like '%織' or com_district like '%育' then concat(com_district,'-',com_industry) else com_industry end as com_industry_total
,replace(com_addr,'地 址:','') as com_addr1
,replace(com_phone,'電 話:','') as com_phone1
,replace(com_fax,'傳 真:','') as com_fax1
,replace(com_mobile,'手機(jī):','') as com_mobile1
,replace(com_url,'網(wǎng)址:','') as com_url1
,replace(com_email,'郵箱:','') as com_email1
,replace(com_contactor,'聯(lián)系人:','') as com_contactor1
,replace(com_emploies_nums,'公司人數(shù):','') as com_emploies_nums1
,replace(com_reg_capital,'注冊(cè)資金:萬(wàn)','') as com_reg_capital1
,replace(com_type,'經(jīng)濟(jì)類型:','') as com_type1
,replace(com_product,'公司產(chǎn)品:','') as com_product1
,replace(com_desc,'公司簡(jiǎn)介:','') as com_desc1
from s_socom_data as a

2.5、表輸出

表輸出設(shè)置注意事項(xiàng)

注意事項(xiàng):

① 涉及爬蟲(chóng)增量操作 不要勾選裁剪表選項(xiàng)

②數(shù)據(jù)連接問(wèn)題 選擇表輸出中表所在的數(shù)據(jù)庫(kù)

③字段映射問(wèn)題 確保數(shù)據(jù)流中的字段和物理表的字段數(shù)量一致 對(duì)應(yīng)一致

三、kettle轉(zhuǎn)換etl2清洗

首先建表增加了4個(gè)字段 演示步驟在視頻里

字段索引 沒(méi)有提 索引算法建議用BTREE算法增強(qiáng)查詢效率

主要針對(duì)etl1 生成的新的com_industry進(jìn)行字段拆分 清洗

3.1.kettle文件名:trans_etl2_socom_data

3.2.包括控件:表輸入>>>表輸出

3.3.數(shù)據(jù)流方向:etl1_socom_data>>>>etl2_socom_data

注意事項(xiàng):

① 涉及爬蟲(chóng)增量操作 不要勾選裁剪表選項(xiàng)

②數(shù)據(jù)連接問(wèn)題 選擇表輸出中表所在的數(shù)據(jù)庫(kù)

③字段映射問(wèn)題 確保數(shù)據(jù)流中的字段和物理表的字段數(shù)量一致 對(duì)應(yīng)一致

kettle轉(zhuǎn)換2截圖

3.4、SQL腳本 對(duì)com_industry進(jìn)行拆分 完成所有字段清洗 注冊(cè)資金字段時(shí)間關(guān)系沒(méi)有進(jìn)行細(xì)致拆解 調(diào)整代碼即可

select a.*,
case 
#行業(yè)為''的值 置為空
when length(com_industry)=0 then null
#其他的取第一個(gè)-分隔符之前
else substring_index(com_industry,'-',1) end as com_industry1,
case 
when length(com_industry)-length(replace(com_industry,'-',''))=0 then null
#'交通運(yùn)輸、倉(cāng)儲(chǔ)和郵政業(yè)-' 這種值 行業(yè)2 也置為null
when length(com_industry)-length(replace(com_industry,'-',''))=1 and length(substring_index(com_industry,'-',-1))=0 then null
when length(com_industry)-length(replace(com_industry,'-',''))=1 then substring_index(com_industry,'-',-1)
else substring_index(substring_index(com_industry,'-',2),'-',-1)
end as com_industry2,
case 
when length(com_industry)-length(replace(com_industry,'-',''))<=1 then null
when length(com_industry)-length(replace(com_industry,'-',''))=2 then substring_index(com_industry,'-',-1)
else substring_index(substring_index(com_industry,'-',3),'-',-1)
end as com_industry3,
case 
when length(com_industry)-length(replace(com_industry,'-',''))<=2 then null
else substring_index(com_industry,'-',-1)
end as com_industry4
from etl1_socom_data as a

四、清洗效果質(zhì)量檢查

4.1爬蟲(chóng)數(shù)據(jù)源數(shù)據(jù)和網(wǎng)站數(shù)據(jù)是否相符

如果本身工作是爬蟲(chóng)和數(shù)據(jù)處理在一起處理,抓取的時(shí)候其實(shí)已經(jīng)判斷,此步驟可以省略,如果對(duì)接上游爬蟲(chóng)同事,這一步首先判斷,不然清洗也是無(wú)用功,一般都要求爬蟲(chóng)同事存儲(chǔ)請(qǐng)求的url便于后面數(shù)據(jù)處理查看數(shù)據(jù)質(zhì)量

4.2計(jì)算爬蟲(chóng)數(shù)據(jù)源和各etl清洗數(shù)據(jù)表數(shù)據(jù)量

注:SQL腳本中沒(méi)有經(jīng)過(guò)聚合過(guò)濾 3個(gè)表數(shù)據(jù)量應(yīng)相等

4.2.1、sql查詢 下面表我是在同一數(shù)據(jù)庫(kù)中 如果不在同一數(shù)據(jù)庫(kù) from 后面應(yīng)加上表所在的數(shù)據(jù)庫(kù)名稱

不推薦數(shù)據(jù)量大的時(shí)候使用

select count(1) from s_socom_data
union all
select count(1) from etl1_socom_data
union all
select count(1) from etl2_socom_data

4.2.2 根據(jù) kettle轉(zhuǎn)換執(zhí)行完畢以后 表輸出總量對(duì)比

kettle表輸出總數(shù)據(jù)量

4.3查看etl清洗質(zhì)量

確保前兩個(gè)步驟已經(jīng)無(wú)誤,數(shù)據(jù)處理負(fù)責(zé)的etl清洗工作自查開(kāi)始 針對(duì)數(shù)據(jù)源清洗的字段 寫(xiě)腳本檢查 socom網(wǎng)站主要是對(duì)地區(qū) 和行業(yè)進(jìn)行了清洗 對(duì)其他字段做了替換多余字段處理 ,因此采取腳本檢查,

找到page_url和網(wǎng)站數(shù)據(jù)進(jìn)行核查

where里面這樣寫(xiě)便于查看某個(gè)字段的清洗情況

select * 
from etl2_socom_data 
where com_district is null and length(com_industry)-length(replace(com_industry,'-',''))=3

http://www.socom.cn/company/7320798.html此頁(yè)面數(shù)據(jù)和etl2_socom_data表最終清洗數(shù)據(jù)對(duì)比

網(wǎng)站頁(yè)面數(shù)據(jù)

etl2_socom_data表數(shù)據(jù)

清洗工作完成。

以上這篇基于python爬蟲(chóng)數(shù)據(jù)處理(詳解)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python讀寫(xiě)Excel文件庫(kù)的實(shí)現(xiàn)示例

    Python讀寫(xiě)Excel文件庫(kù)的實(shí)現(xiàn)示例

    本文主要介紹了Python讀寫(xiě)Excel文件庫(kù)的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-08-08
  • python定時(shí)復(fù)制遠(yuǎn)程文件夾中所有文件

    python定時(shí)復(fù)制遠(yuǎn)程文件夾中所有文件

    這篇文章主要為大家詳細(xì)介紹了python定時(shí)復(fù)制遠(yuǎn)程文件夾中所有文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-04-04
  • Python實(shí)現(xiàn)的徑向基(RBF)神經(jīng)網(wǎng)絡(luò)示例

    Python實(shí)現(xiàn)的徑向基(RBF)神經(jīng)網(wǎng)絡(luò)示例

    這篇文章主要介紹了Python實(shí)現(xiàn)的徑向基(RBF)神經(jīng)網(wǎng)絡(luò),結(jié)合完整實(shí)例形式分析了Python徑向基(RBF)神經(jīng)網(wǎng)絡(luò)定義與實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2018-02-02
  • 對(duì)Python w和w+權(quán)限的區(qū)別詳解

    對(duì)Python w和w+權(quán)限的區(qū)別詳解

    今天小編就為大家分享一篇對(duì)Python w和w+權(quán)限的區(qū)別詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-01-01
  • Django Admin中增加導(dǎo)出Excel功能過(guò)程解析

    Django Admin中增加導(dǎo)出Excel功能過(guò)程解析

    這篇文章主要介紹了Django Admin中增加導(dǎo)出Excel功能過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-09-09
  • 解決Python 中JSONDecodeError: Expecting value: line 1 column 1 (char 0)錯(cuò)誤

    解決Python 中JSONDecodeError: Expecting value:&n

    這篇文章主要介紹了解決Python 中JSONDecodeError: Expecting value: line 1 column 1 (char 0)錯(cuò)誤問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-03-03
  • 利用?Python?開(kāi)發(fā)一個(gè)?Python?解釋器

    利用?Python?開(kāi)發(fā)一個(gè)?Python?解釋器

    這篇文章主要介紹了利用?Python?開(kāi)發(fā)一個(gè)?Python?解釋器,在本文中,我們將設(shè)計(jì)一個(gè)可以執(zhí)行算術(shù)運(yùn)算的解釋器。下面我們大家一起來(lái)看看吧</P><P>
    2022-01-01
  • Python如何在類中定義裝飾器

    Python如何在類中定義裝飾器

    這篇文章主要介紹了Python如何在類中定義裝飾器的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • jupyter notebook 增加kernel教程

    jupyter notebook 增加kernel教程

    這篇文章主要介紹了jupyter notebook 增加kernel教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-04-04
  • python中的多cpu并行編程

    python中的多cpu并行編程

    這篇文章主要介紹了python中的多cpu并行編程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05

最新評(píng)論

新闻| 麦盖提县| 新余市| 巫溪县| 青田县| 五莲县| 巧家县| 合江县| 崇仁县| 濮阳市| 中江县| 轮台县| 友谊县| 嘉善县| 蓬莱市| 高雄市| 于田县| 黔江区| 随州市| 青海省| 夹江县| 乾安县| 鄂伦春自治旗| 金秀| 安康市| 班玛县| 谷城县| 灯塔市| 安庆市| 绍兴县| 通榆县| 桂林市| 嘉鱼县| 汽车| 黑山县| 冀州市| 贵溪市| 黄冈市| 平度市| 军事| 永城市|