數據特征分析-分布分析

分布分析用于研究數據的分布特征,常用分析方法:

1、極差

2、頻率分布

3、分組組距及組數

df = pd.DataFrame({'編碼':['001','002','003','004','005','006','007','008','009','010','011','012','013','014','015'],\'小區':['A村','B村','C村','D村','E村','A村','B村','C村','D村','E村','A村','B村','C村','D村','E村'],\'朝向':['south','east_north','south','east_south','eath_south','north','east_north','west_north','south','west','north','east_north','south','south','east'],\'單價':[7374,6435,6643,5874,6738,6453,5733,6034,5276,5999,6438,5864,6099,5699,6999],\'首付':[15,7.5,18,10,30,10,18,30,40,30,20,22,29,30,40],\'總價':[50,65,68,73,80,55,45,70,59,57,40,60,50,48,60],\'經度':[114.0,114.6,114.8,114.2,114.5,114.3,114.4,114.7,114.9,114.1,114.8,114.2,114.5,114.3,114.8],\'緯度':[22.0,22.4,22.6,22.8,22.2,22.1,22.7,22.5,22.9,22.3,22.8,22.2,22.1,22.7,22.5]    }) 

?

先對總體做關于經緯度的散點圖

plt.scatter(df['經度'],df['緯度'],s = df['單價']/50,c = df['總價'],cmap='Greens')   #原點的大小可以表示單價,越大單價越高;顏色深淺可以表示總價,越深總價越高

?

?求總價、單價和首付的極差

def d_range(df,*cols):krange = []for c in cols:crange = df[c].max() - df[c].min()krange.append(crange)return ('%s極差:%s\n%s極差:%s\n%s極差:%s'%(cols[0],krange[0],cols[1],krange[1],cols[2],krange[2]))
print(d_range(df,'總價','單價','首付'))
# 總價極差:40
# 單價極差:2098
# 首付極差:32.5

?

單價和總價的頻率分布

fig,axes = plt.subplots(1,2,figsize = (10,4))
df['單價'].hist(bins = 8,ax = axes[0])
df['總價'].hist(bins = 8,ax = axes[1])

?

將總價分為8個區間,求出每個區間的頻數、頻率,并求出累計頻率

# 頻率分布,分組區間
total_range = pd.cut(df['總價'],8)   #通過cut將總價分為8個區間
total_range_count = total_range.value_counts(sort=False)   #求每個區間的個數,結果為一個Seris,不按列的大小排序
total_range_s = pd.DataFrame(total_range_count)  #將Seris轉化為DataFrame,生成一個用于統計總價的DataFrame
# # total_range_s.rename(columns = {total_range_count.name:'頻數',inplace = True})
total_range_s.columns = ['頻數']  #給轉化后的DataFrame重命名列
df['區間'] = total_range.values  #給原數據加一列區間
total_range_s['頻率'] = total_range_s['頻數']/total_range_s['頻數'].sum()  #求總價在每個區間出現的頻率
total_range_s['累計頻率'] = total_range_s['頻率'].cumsum()   ##求總價在每個區間的累計頻率
total_range_s['頻率%'] = total_range_s['頻率'].apply(lambda x:'%.2f%%'%(100*x))  #格式化頻率列,顯示為2位百分數
total_range_s['累計頻率%'] = total_range_s['累計頻率'].apply(lambda x:'%.2f%%'%(100*x))#格式化頻率列,顯示為2位百分數
total_range_s.style.bar(subset = ['頻率','累計頻率'])

?

?對每個總價區間出現的頻率做柱狀圖

total_range_s['頻率'].plot(kind = 'bar',alpha = 0.8,title ='total price interval')
x = range(len(total_range_s.index))
for i,j,k in zip(x,total_range_s['頻率'],total_range_s['頻數']):plt.text(i,j+0.01,k)

?

?

對于單個字段比如朝向,做頻率統計分析

# 頻率分布 定性字段
cx = df['朝向'].value_counts()
cx_s = pd.DataFrame(cx)
cx_s.columns = ['頻數']
cx_s['頻率'] = cx_s['頻數']/cx_s['頻數'].sum()
cx_s['累計頻率'] = cx_s['頻率'].cumsum()
cx_s['頻率%'] = cx_s['頻率'].apply(lambda x:'%.2f%%'%(100*x))
cx_s['累計頻率%'] = cx_s['累計頻率'].apply(lambda x:'%.2f%%'%(100*x))
cx_s.style.bar(subset = ['頻率','累計頻率'] )

?

?對朝向做柱狀圖和餅圖

fig,axes = plt.subplots(1,2,figsize = (10,4))
cx_s['頻率'].plot(kind = 'bar',ax = axes[0],title = 'direction bar')   plt.pie(cx_s['頻數'],labels=cx_s.index,autopct='%2.f%%')
plt.title('direction pie')

?

轉載于:https://www.cnblogs.com/Forever77/p/11344050.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391721.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391721.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391721.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

開發工具總結(2)之全面總結Android Studio2.X的填坑指南

前言:好多 Android 開發者都在說Android Studio太坑了,老是出錯,導致開發進度變慢,出錯了又不知道怎么辦,網上去查各種解決方案五花八門,有些可以解決問題,有些就是轉來轉去的寫的很粗糙&#x…

無聊的一天_一人互聯網公司背后的無聊技術

無聊的一天Listen Notes is a podcast search engine and database. The technology behind Listen Notes is actually very very boring. No AI, no deep learning, no blockchain. “Any man who must say I am using AI is not using True AI” :)Listen Notes是一個播客搜索…

如何在Pandas中使用Excel文件

From what I have seen so far, CSV seems to be the most popular format to store data among data scientists. And that’s understandable, it gets the job done and it’s a quite simple format; in Python, even without any library, one can build a simple CSV par…

Js實現div隨鼠標移動的方法

HTML: <div id"odiv" style" COLOR: #666; padding: 2px 8px; FONT-SIZE: 12px; MARGIN-RIGHT: 5px; position: absolute; background: #fff; display: block; border: 1px solid #666; top: 50px; left: 10px;"> Move_Me</div>第一種&…

leetcode 867. 轉置矩陣

給你一個二維整數數組 matrix&#xff0c; 返回 matrix 的 轉置矩陣 。 矩陣的 轉置 是指將矩陣的主對角線翻轉&#xff0c;交換矩陣的行索引與列索引。 示例 1&#xff1a; 輸入&#xff1a;matrix [[1,2,3],[4,5,6],[7,8,9]] 輸出&#xff1a;[[1,4,7],[2,5,8],[3,6,9]] …

數據特征分析-對比分析

對比分析是對兩個互相聯系的指標進行比較。 絕對數比較(相減)&#xff1a;指標在量級上不能差別過大&#xff0c;常用折線圖、柱狀圖 相對數比較(相除)&#xff1a;結構分析、比例分析、空間比較分析、動態對比分析 df pd.DataFrame(np.random.rand(30,2)*1000,columns[A_sale…

Linux基線合規檢查中各文件的作用及配置腳本

1./etc/motd 操作&#xff1a;echo " Authorized users only. All activity may be monitored and reported " > /etc/motd 效果&#xff1a;telnet和ssh登錄后的輸出信息 2. /etc/issue和/etc/issue.net 操作&#xff1a;echo " Authorized users only. All…

tableau使用_使用Tableau升級Kaplan-Meier曲線

tableau使用In a previous article, I showed how we can create the Kaplan-Meier curves using Python. As much as I love Python and writing code, there might be some alternative approaches with their unique set of benefits. Enter Tableau!在上一篇文章中 &#x…

踩坑 net core

webclient 可以替換為 HttpClient 下載獲取url的內容&#xff1a; 證書&#xff1a; https://stackoverflow.com/questions/40014047/add-client-certificate-to-net-core-httpclient 轉載于:https://www.cnblogs.com/zxs-onestar/p/7340386.html

我從參加#PerfMatters會議中學到的東西

by Stacey Tay通過史黛西泰 我從參加#PerfMatters會議中學到的東西 (What I learned from attending the #PerfMatters conference) 從前端的網絡運行情況發布會上的注意事項 (Notes from a front-end web performance conference) This week I had the privilege of attendin…

修改innodb_flush_log_at_trx_commit參數提升insert性能

最近&#xff0c;在一個系統的慢查詢日志里發現有個insert操作很慢&#xff0c;達到秒級&#xff0c;并且是比較簡單的SQL語句&#xff0c;把語句拿出來到mysql中直接執行&#xff0c;速度卻很快。 這種問題一般不是SQL語句本身的問題&#xff0c;而是在具體的應用環境中&#…

leetcode 1178. 猜字謎(位運算)

外國友人仿照中國字謎設計了一個英文版猜字謎小游戲&#xff0c;請你來猜猜看吧。 字謎的迷面 puzzle 按字符串形式給出&#xff0c;如果一個單詞 word 符合下面兩個條件&#xff0c;那么它就可以算作謎底&#xff1a; 單詞 word 中包含謎面 puzzle 的第一個字母。 單詞 word…

Nexus3.x.x上傳第三方jar

exus3.x.x上傳第三方jar&#xff1a; 1. create repository 選擇maven2(hosted)&#xff0c;說明&#xff1a; proxy&#xff1a;即你可以設置代理&#xff0c;設置了代理之后&#xff0c;在你的nexus中找不到的依賴就會去配置的代理的地址中找hosted&#xff1a;你可以上傳你自…

責備的近義詞_考試結果危機:我們應該責備算法嗎?

責備的近義詞I’ve been considering writing on the topic of algorithms for a little while, but with the Exam Results Fiasco dominating the headline news in the UK during the past week, I felt that now is the time to look more closely into the subject.我一直…

電腦如何設置終端設置代理_如何設置一個嚴肅的Kubernetes終端

電腦如何設置終端設置代理by Chris Cooney克里斯庫尼(Chris Cooney) 如何設置一個嚴肅的Kubernetes終端 (How to set up a serious Kubernetes terminal) 所有k8s書呆子需要的CLI工具 (All the CLI tools a growing k8s nerd needs) Kubernetes comes pre-packaged with an ou…

spring cloud(二)

1. Feign應用 Feign的作用&#xff1b;使用Feign實現consumer-demo代碼中調用服務 導入啟動器依賴&#xff1b;開啟Feign功能&#xff1b;編寫Feign客戶端&#xff1b;編寫一個處理器ConsumerFeignController&#xff0c;注入Feign客戶端并使用&#xff1b;測試 <dependen…

c/c++編譯器的安裝

MinGW(Minimalist GNU For Windows)是個精簡的Windows平臺C/C、ADA及Fortran編譯器&#xff0c;相比Cygwin而言&#xff0c;體積要小很多&#xff0c;使用較為方便。 MinGW最大的特點就是編譯出來的可執行文件能夠獨立在Windows上運行。 MinGW的組成&#xff1a; 編譯器(支持C、…

滲透工具

滲透工具 https://blog.csdn.net/Fly_hps/article/details/89306104 查詢工具 https://blog.csdn.net/Fly_hps/article/details/89070552 轉載于:https://www.cnblogs.com/liuYGoo/p/11347693.html

numpy 線性代數_數據科學家的線性代數—用NumPy解釋

numpy 線性代數Machine learning and deep learning models are data-hungry. The performance of them is highly dependent on the amount of data. Thus, we tend to collect as much data as possible in order to build a robust and accurate model. Data is collected i…

spring 注解方式配置Bean

概要&#xff1a; 再classpath中掃描組件 組件掃描&#xff08;component scanning&#xff09;&#xff1a;Spring可以從classpath下自己主動掃描。偵測和實例化具有特定注解的組件特定組件包含&#xff1a; Component&#xff1a;基本注解。標示了一個受Spring管理的組件&…