国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

Python實(shí)現(xiàn)的北京積分落戶數(shù)據(jù)分析示例

瀏覽:10日期:2022-07-31 18:39:25

本文實(shí)例講述了Python實(shí)現(xiàn)的北京積分落戶數(shù)據(jù)分析。分享給大家供大家參考,具體如下:

北京積分落戶狀況 獲取數(shù)據(jù)(爬蟲/文件下載)—> 分析 (維度—指標(biāo)) 從公司維度分析不同公司對(duì)落戶人數(shù)指標(biāo)的影響 , 即什么公司落戶人數(shù)最多也更容易落戶 從年齡維度分析不同年齡段對(duì)落戶人數(shù)指標(biāo)影響 , 即什么年齡段落戶人數(shù)最多也更容易落戶 從百家姓維度分析不同姓對(duì)落戶人數(shù)的指標(biāo)影響 , 即什么姓的落戶人數(shù)最多即也更容易落戶 不同分?jǐn)?shù)段的占比情況

# 導(dǎo)入庫(kù)import numpy as npimport pandas as pdimport matplotlib.pyplot as pltfrom matplotlib import font_manager

#讀取數(shù)據(jù)(文件) , 并查看數(shù)據(jù)相應(yīng)結(jié)構(gòu)和格式lh_data = pd.read_csv(’./bj_luohu.csv’,index_col=’id’,usecols=(0,1,2,3,4))lh_data.describe()

Python實(shí)現(xiàn)的北京積分落戶數(shù)據(jù)分析示例

# 1. 公司維度---人數(shù)指標(biāo)# 對(duì)公司進(jìn)行分組聚合 , 并查看分?jǐn)?shù)的相關(guān)數(shù)據(jù) (個(gè)數(shù) , 總分?jǐn)?shù) , 平均分 , 人數(shù)占比)group_company = lh_data.groupby(’company’,as_index=False)[’score’].agg([’count’,’sum’,’mean’]).sort_values(’count’,ascending=False)#更改列名稱group_company.rename(columns={’count’:’people_num’,’sum’:’score_sum’,’mean’:’score_mean’},inplace=True)#定一個(gè)函數(shù) , 得到占比def num_percent(people_num=1,people_sum=1): return str(’%.2f’%(people_num / people_sum * 100))+’%’#增加一個(gè)占比列g(shù)roup_company[’people_percent’] = group_company[’people_num’].apply(num_percent,people_sum=lh_data[’name’].count())#查看只有一個(gè)人落戶的公司 布爾索引group_company[group_company[’people_num’] == 1]group_company.head(10)

Python實(shí)現(xiàn)的北京積分落戶數(shù)據(jù)分析示例

# 2.年齡維度----人數(shù)指標(biāo)#將出生年月轉(zhuǎn)為年齡lh_data[’age’] = (pd.to_datetime(’2019-09’) - pd.to_datetime(lh_data[’birthday’])) / pd.Timedelta(’365 days’)# 分桶l(fā)h_data.describe()bins_age = pd.cut(lh_data[’age’],bins=np.arange(30,70,5))bins_age_group = lh_data[’age’].groupby(bins_age).count()bins_age_group.index = [str(i.left) + ’~’ + str(i.right) for i in bins_age_group.index]bins_age_group.plot(kind=’bar’,alpha=1,rot=60,grid=0.2)

Python實(shí)現(xiàn)的北京積分落戶數(shù)據(jù)分析示例

# 3. 姓維度----人數(shù)指標(biāo)# 增加姓列#定義一個(gè)函數(shù) 得到姓名的姓def get_fname(name): if len(str(name)) <= 3: return str(name[0]) else: return str(name[0:2])lh_data[’fname’] = lh_data[’name’].apply(get_fname)# 對(duì)姓進(jìn)行分組group_fname = lh_data.groupby(’fname’)[’score’].agg([’count’,’sum’,’mean’]).sort_values(’count’,ascending=False)# 更改列名稱group_fname.rename(columns={’count’:’people_num’,’sum’:’people_sum’,’mean’:’score_mean’},inplace=True)# 增加占比列g(shù)roup_fname[’people_percent’] = group_fname[’people_num’].apply(num_percent,people_sum=lh_data[’name’].count())group_fname.head(10)

Python實(shí)現(xiàn)的北京積分落戶數(shù)據(jù)分析示例

# 4. 查看分?jǐn)?shù)段占比 # 分桶 將分?jǐn)?shù)劃分為一個(gè)個(gè)的區(qū)間bins_score = pd.cut(lh_data[’score’],np.arange(90,130,5))# 將分?jǐn)?shù)裝入對(duì)應(yīng)的桶里bins_score_group = lh_data[’score’].groupby(bins_score).count()# 更改索引顯示格式bins_score_group.index = [str(i.left)+’~’+str(i.right) for i in bins_score_group.index]bins_score_group.plot(kind=’bar’,alpha=1,rot=60,grid=0.2,title=’score-people_num’,colormap=’RdBu_r’)

Python實(shí)現(xiàn)的北京積分落戶數(shù)據(jù)分析示例

總結(jié)1.pandas的繪圖方法不夠靈活 , 功能也不夠強(qiáng)大 , 最好還是使用matplotlib繪圖2.記住數(shù)據(jù)分析最重要的兩個(gè)方法 分組: groupby() 和 分桶:cut() , 前者一般用于離散的數(shù)據(jù)(姓,公司) , 后者用于連續(xù)數(shù)據(jù) (年齡段,分?jǐn)?shù)段)

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python數(shù)學(xué)運(yùn)算技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進(jìn)階經(jīng)典教程》

希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 阳新县| 都昌县| 柳河县| 烟台市| 磐石市| 建宁县| 宁武县| 府谷县| 嘉峪关市| 伊川县| 北安市| 新津县| 涿州市| 尉氏县| 凭祥市| 沁水县| 兴化市| 定安县| 唐山市| 镇原县| 修文县| 临颍县| 泰和县| 长顺县| 含山县| 东港市| 兴隆县| SHOW| 科尔| 湘潭市| 平江县| 绵竹市| 名山县| 安塞县| 新安县| 桂平市| 东乌珠穆沁旗| 若尔盖县| 平陆县| 淅川县| 靖西县|