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

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

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

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

DataFrame基礎(chǔ)屬性有:values(元素)、index(索引)、columns(列名) 、dtypes(類型)、size(元素個數(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('元素個數(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ù)

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

#使用字典訪問方式order_id=detail[’order_id’]print('訂單詳情表的order_id的形狀:',order_id.shape)#使用訪問屬性的方式 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)#訪問多行數(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訪問方式;

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 這里 沒有單引號的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的長度:’,len(detail))detail.drop(labels=range(1,11),axis=0,inplace=True)print(’刪除1~10行 后 detail的長度:’,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)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 日韩性大片免费 | 九九视频高清视频免费观看 | 欧美精品网站 | 精品国产福利 | 成人午夜兔费观看网站 | 久久久久免费视频 | 亚洲精品久久久久久久777 | 午夜欧美精品久久久久久久久 | 色播亚洲精品网站 亚洲第一 | 中文字幕日韩精品有码视频 | 2022国产精品自拍 | 日韩精品另类天天更新影院 | 亚洲美女视频网站 | 国产成人综合欧美精品久久 | 欧美一区二区三区男人的天堂 | 久久香蕉国产线看免费 | 真实国产乱子伦高清 | 91九九| 国产在视频线在精品 | 成人欧美精品一区二区不卡 | 不卡一区二区在线观看 | wwwxx在线| 2020国产微拍精品一区二区 | 久久精品网站免费观看 | 亚洲精品中文一区不卡 | 亚洲精品国产第一区二区多人 | 国产成人综合久久精品亚洲 | 天天看夜夜看 | 最新精品亚洲成a人在线观看 | 欧美精品束缚一区二区三区 | 欧美色综合高清视频在线 | 九九免费精品视频在这里 | 国产美女91视频 | 欧美一级大片免费看 | 黄色三区 | 国产一区二区在线播放 | 新婚第一次一级毛片 | 日p免费视频 | 2022国产精品网站在线播放 | 亚洲视频天堂 | 求欧美精品网址 |