99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話(huà):13121318867

登錄
首頁(yè)精彩閱讀盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)
盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)
2019-11-07
收藏
盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)

作者 | 劉順祥

來(lái)源 | 數(shù)據(jù)分析1480

這一期將分享我認(rèn)為比較常規(guī)的100個(gè)實(shí)用函數(shù),這些函數(shù)大致可以分為六類(lèi),分別是統(tǒng)計(jì)匯總函數(shù)、數(shù)據(jù)清洗函數(shù)、數(shù)據(jù)篩選、繪圖與元素級(jí)運(yùn)算函數(shù)、時(shí)間序列函數(shù)和其他函數(shù)。


統(tǒng)計(jì)匯總函數(shù)

數(shù)據(jù)分析過(guò)程中,必然要做一些數(shù)據(jù)的統(tǒng)計(jì)匯總工作,那么對(duì)于這一塊的數(shù)據(jù)運(yùn)算有哪些可用的函數(shù)可以幫助到我們呢?具體看如下幾張表。

盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)
盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)
import pandas as pd
import numpy as np
x = pd.Series(np.random.normal(2,3,1000))
y = 3*x + 10 + pd.Series(np.random.normal(1,2,1000))
# 計(jì)算x與y的相關(guān)系數(shù)
print(x.corr(y))
# 計(jì)算y的偏度
print(y.skew())
# 計(jì)算y的統(tǒng)計(jì)描述值
print(x.describe())
z = pd.Series(['A','B','C']).sample(n = 1000, replace = True)
# 重新修改z的行索引
z.index = range(1000)
# 按照z分組,統(tǒng)計(jì)y的組內(nèi)平均值
y.groupby(by = z).aggregate(np.mean)
盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)
盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)
# 統(tǒng)計(jì)z中個(gè)元素的頻次
print(z.value_counts())
a = pd.Series([1,5,10,15,25,30])
# 計(jì)算a中各元素的累計(jì)百分比
print(a.cumsum() / a.cumsum()[a.size - 1])

盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)


數(shù)據(jù)清洗函數(shù)

同樣,數(shù)據(jù)清洗工作也是必不可少的工作,在如下表格中羅列了常有的數(shù)據(jù)清洗的函數(shù)。

盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)
x = pd.Series([10,13,np.nan,17,28,19,33,np.nan,27])
#檢驗(yàn)序列中是否存在缺失值
print(x.hasnans)
# 將缺失值填充為平均值
print(x.fillna(value = x.mean()))
# 前向填充缺失值
print(x.ffill())
盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)
盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)
income = pd.Series(['12500元','8000元','8500元','15000元','9000元'])
# 將收入轉(zhuǎn)換為整型
print(income.str[:-1].astype(int))
gender = pd.Series(['男','女','女','女','男','女'])
# 性別因子化處理
print(gender.factorize())
house = pd.Series(['大寧金茂府 | 3室2廳 | 158.32平米 | 南 | 精裝',
 '昌里花園 | 2室2廳 | 104.73平米 | 南 | 精裝',
 '紡大小區(qū) | 3室1廳 | 68.38平米 | 南 | 簡(jiǎn)裝'])
# 取出二手房的面積,并轉(zhuǎn)換為浮點(diǎn)型
house.str.split('|').str[2].str.strip().str[:-2].astype(float)

盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)


數(shù)據(jù)篩選

數(shù)據(jù)分析中如需對(duì)變量中的數(shù)值做子集篩選時(shí),可以巧妙的使用下表中的幾個(gè)函數(shù),其中部分函數(shù)既可以使用在序列身上,也基本可以使用在數(shù)據(jù)框?qū)ο笾小?/span>

盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)
np.random.seed(1234)
x = pd.Series(np.random.randint(10,20,10))
# 篩選出16以上的元素
print(x.loc[x > 16])
print(x.compress(x > 16))
# 篩選出13~16之間的元素
print(x[x.between(13,16)])
# 取出最大的三個(gè)元素
print(x.nlargest(3))
y = pd.Series(['ID:1 name:張三 age:24 income:13500',
 'ID:2 name:李四 age:27 income:25000',
 'ID:3 name:王二 age:21 income:8000'])
# 取出年齡,并轉(zhuǎn)換為整數(shù)
print(y.str.findall('age:(d+)').str[0].astype(int))

盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)


繪圖與元素級(jí)函數(shù)

盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)
np.random.seed(123)
import matplotlib.pyplot as plt
x = pd.Series(np.random.normal(10,3,1000))
# 繪制x直方圖
x.hist()
# 顯示圖形
plt.show()
# 繪制x的箱線圖
x.plot(kind='box')
plt.show()
installs = pd.Series(['1280萬(wàn)','6.7億','2488萬(wàn)','1892萬(wàn)','9877','9877萬(wàn)','1.2億'])
# 將安裝量統(tǒng)一更改為“萬(wàn)”的單位
def transform(x):
 if x.find('億') != -1:
 res = float(x[:-1])*10000
 elif x.find('萬(wàn)') != -1:
 res = float(x[:-1])
 else:
 res = float(x)/10000
 return res
installs.apply(transform)

盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)

盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)

盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)


時(shí)間序列函數(shù)

盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)
盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)

盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)


其他函數(shù)

盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)
import numpy as np
import pandas as pd
np.random.seed(112)
x = pd.Series(np.random.randint(8,18,6))
print(x)
# 對(duì)x中的元素做一階差分
print(x.diff())
# 對(duì)x中的元素做降序處理
print(x.sort_values(ascending = False))
y = pd.Series(np.random.randint(8,16,100))
# 將y中的元素做排重處理,并轉(zhuǎn)換為列表對(duì)象
y.unique().tolist()
盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)
盤(pán)點(diǎn)Pandas 的100個(gè)常用函數(shù)

數(shù)據(jù)分析咨詢(xún)請(qǐng)掃描二維碼

若不方便掃碼,搜微信號(hào):CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢(xún)
客服在線
立即咨詢(xún)
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個(gè)參數(shù)驗(yàn)證碼對(duì)象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個(gè)配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶(hù)后臺(tái)檢測(cè)極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時(shí)表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說(shuō)明請(qǐng)參見(jiàn):http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計(jì)時(shí)完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請(qǐng)輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請(qǐng)輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }