国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

Python中快速掌握Data Frame的常用操作

瀏覽:73日期:2022-06-23 16:58:35
掌握Data Frame的常用操作一. 查看DataFrame的常用屬性

DataFrame基礎(chǔ)屬性有:values(元素)、index(索引)、columns(列名) 、dtypes(類型)、size(元素個(gè)數(shù))、ndim(維度數(shù))和 shape(形狀大小尺寸),還有使用T屬性 進(jìn)行轉(zhuǎn)置

import pandas as pddetail=pd.read_excel(’E:datameal_order_detail.xlsx’) #讀取數(shù)據(jù),使用read_excel 函數(shù)調(diào)用# print(detail)print('索引',detail.index)print('所以 值 :',detail.values)print('所以列名:',detail.columns)print('數(shù)據(jù)類型:',detail.dtypes)print('元素個(gè)數(shù):',detail.size)print('維度:',detail.ndim)print('形狀大小 尺寸:',detail.shape)#使用T屬性 進(jìn)行轉(zhuǎn)置print('轉(zhuǎn)置前的形狀:',detail.shape)數(shù)據(jù)print('轉(zhuǎn)置后的形狀:',detail.T.shape)二. 查改增刪DataFrame數(shù)據(jù)

查看訪問(wèn)DataFramezhon’的數(shù)據(jù)(1.1)DataFrame數(shù)據(jù)的基本查看方式

#使用字典訪問(wèn)方式order_id=detail[’order_id’]print('訂單詳情表的order_id的形狀:',order_id.shape)#使用訪問(wèn)屬性的方式 dishes_name=detail.dishes_nameprint('訂單詳情表中的dishes_name的形狀:',dishes_name.shape)#DataFrame 單列多行的數(shù)據(jù)獲取dishes_name5=detail[’dishes_name’][:5]print(dishes_name5)#多列多行數(shù)據(jù)orderDish=detail[[’order_id’,’dishes_name’]][:5]print(orderDish)#訪問(wèn)多行數(shù)據(jù)order5=detail[:][1:6]print('訂單詳情表中的1~6行元素的數(shù)據(jù):n',order5)#使用DataFrame的head和tail方法獲取多行數(shù)據(jù)print(’訂單詳情表中前5行數(shù)據(jù):n’,detail.head())#head()里面沒有參數(shù)的話,默認(rèn)為5行print(’訂單詳情表中后5行數(shù)據(jù):n’,detail.tail()) #tail()里面沒有參數(shù)的話,默認(rèn)為5行

(1.2) .DataFrame的loc和iloc訪問(wèn)方式;

dishes_name1=detail.loc[:,’dishes_name’] #DataFrame.loc[行索引名稱或條件,列索引名稱]print('使用loc提取dishes_name列的size:',dishes_name1.size)dishes_name2=detail.iloc[:,3] #DataFrame.iloc[行索引位置,列索引位置]print('使用iloc提取第3列的size:',dishes_name2.size)#使用loc、iloc 實(shí)現(xiàn)多列切片orderDish1=detail.loc[:,[’order_id’,’dishes_name’]]print(orderDish1.size)orderDish2=detail.iloc[:,[1,3]]print(orderDish2.size)#使用loc、iloc 實(shí)現(xiàn)花式切片print('列名為order_id和dishes_name 的行名為3的數(shù)據(jù):n',detail.loc[3,[’order_id’,’dishes_name’]])print(’列名為order_id和dishes_name 行名為2、3、4、5、6的數(shù)據(jù)為:n’,detail.loc[2:6,[’order_id’,’dishes_name’]])print(’列名1和3,行位置為3的數(shù)據(jù)為:n’,detail.iloc[3,[1,3]]) #這里為什么不可以loc函數(shù), #因?yàn)閘oc函數(shù)傳入的是列索引的名稱(或行的名稱或條件),而iloc傳入的是位置print(’列位置為1和3,行位置為2,3,4,5,6的數(shù)據(jù)和:n’,detail.iloc[2:7,[1,3]])#這里是位置索引,7是取不到的#使用loc和iloc函數(shù)實(shí)現(xiàn)條件切片print(’detail中order_id為458的dishes_name為:n’,detail.loc[detail[’order_id’]==458,[’order_id’,’dishes_name’]]) #使用了locprint('detail中order_id為458 的第1、5列的數(shù)據(jù)為:n',detail.iloc[(detail[’order_id’]==458).values,[1,5]])#values 獲取元素 #使用iloc函數(shù)

(1.3).ix切片方法

#使用loc、iloc、ix 實(shí)現(xiàn)切片 比較(DataFrame.ix[行的索引或位置或條件,列索引名稱和位置])print(’列名為dishes_name行名為2,3,4,5,6的數(shù)據(jù)為:n’,detail.loc[2:6,[’dishes_name’]])print(’列位置為5行名為2~6的數(shù)據(jù)為:n’,detail.iloc[2:6,5])print(’列位置為5行名為2~6的數(shù)據(jù)為:n’,detail.ix[2:6,5])

2.更改DataFame中的數(shù)據(jù)

#將order_id為458 的改成 45800detail.loc[detail[’order_id’]==458,’order_id’] = 45800 #45800 這里 沒有單引號(hào)的print(’更改后detail中的order_id為 458 的:n’,detail.loc[detail[’order_id’]==458,’order_id’])print(’更改后detail中的order_id為 45800 的:n’,detail.loc[detail[’order_id’]==45800,’order_id’])detail.loc[detail[’order_id’]==45800,’order_id’] = 458

3.為DataFrame增添數(shù)據(jù)

#新增一列非定值detail[’payment’]=detail[’counts’]*detail[’amounts’]print(’detail新增列payment的前5行數(shù)據(jù)為:n’,detail[’payment’].head())#新增一列定值detail[’pay_way’]=’現(xiàn)金支付’print(’detail新增列的前5行的數(shù)據(jù)為:n’,detail[’pay_way’].head())``4.刪除某行或某列的數(shù)據(jù)(drop)#刪除某列print(’刪除pay_way前 detail中的列索引為:n’,detail.columns)detail.drop(labels=’pay_way’,axis=1,inplace=True)print(’刪除pay_way后 detail中的列索引為:n’,detail.columns)#刪除某幾行print(’刪除1~10行 前 detail的長(zhǎng)度:’,len(detail))detail.drop(labels=range(1,11),axis=0,inplace=True)print(’刪除1~10行 后 detail的長(zhǎng)度:’,len(detail))三. 描述分析DataFrame數(shù)據(jù)

1.數(shù)值特征的描述性統(tǒng)計(jì)describe()函數(shù)描述性統(tǒng)計(jì)2.類別類特征的描述性統(tǒng)計(jì)object類型,categroy類型

到此這篇關(guān)于Python中快速掌握Data Frame的常用操作的文章就介紹到這了,更多相關(guān)Python Data Frame的常用操作內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 午夜香蕉网 | 亚洲欧美另类自拍第一页 | 夜夜操影院 | 国产成人99久久亚洲综合精品 | 欧美中文字幕一区 | 精品手机在线 | 久久久日韩精品国产成人 | 国产精品美乳免费看 | 日韩亚洲一区中文字幕在线 | аⅴ资源天堂8在线 | 亚洲人成影院在线高清 | 在线中文字幕精品第5页 | 贵州美女一级纯黄大片 | 高清波多野结衣一区二区三区 | 亚洲国产精品一区二区三区在线观看 | 亚洲成人xxx | 日韩毛片基地 | 国产自约视频 | 国产一级特黄特色aa毛片 | 亚洲精品一区二区三区四区手机版 | 欧美在线小视频 | 国产成人精品日本亚洲网站 | 日本aaaa特级毛片 | 亚洲国产精品久久综合 | 色伊人国产高清在线 | 尤蜜网站在线进入免费 | 成人夜色视频网站在线观看 | 亚洲国产精品a一区二区三区 | 亚洲毛片一级巨乳 | 五月激激激综合网色播免费 | 91久久国产视频 | 最新69成人精品毛片 | 亚洲美女一级片 | 天天综合天天看夜夜添狠狠玩 | 亚洲欧美日本人成在线观看 | 国产精品免费看久久久香蕉 | 欧美日韩一区二区三区在线视频 | 九九九免费视频 | 国产a毛片 | 99热久久国产这里是精品 | 91久久福利国产成人精品 |