《Pandas數(shù)據(jù)處理》課件 1.1.3查詢總價(jià)最高的10個(gè)訂單_第1頁
《Pandas數(shù)據(jù)處理》課件 1.1.3查詢總價(jià)最高的10個(gè)訂單_第2頁
《Pandas數(shù)據(jù)處理》課件 1.1.3查詢總價(jià)最高的10個(gè)訂單_第3頁
《Pandas數(shù)據(jù)處理》課件 1.1.3查詢總價(jià)最高的10個(gè)訂單_第4頁
《Pandas數(shù)據(jù)處理》課件 1.1.3查詢總價(jià)最高的10個(gè)訂單_第5頁
已閱讀5頁,還剩12頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

查詢總價(jià)最高的10個(gè)訂單主講人:徐玲重慶市九龍坡職業(yè)教育中心問題描述在訂單數(shù)據(jù)表1.1.17中,查詢總價(jià)最多的10個(gè)訂單。表1.1.17 訂單數(shù)據(jù)表訂單id數(shù)量名稱描述單價(jià)11ChipsandFreshTomatoSalsaNaN$2.3911Izze[Clementine]$3.3911NantucketNectar[Apple]$3.3911ChipsandTomatillo-GreenChiliSalsaNaN$2.3922ChickenBowl[Tomatillo-RedChiliSalsa(Hot),[BlackBeans...$16.98...............18331SteakBurrito[FreshTomatoSalsa,[Rice,BlackBeans,Sour...$11.7518331SteakBurrito[FreshTomatoSalsa,[Rice,SourCream,Cheese...$11.7518341ChickenSaladBowl[FreshTomatoSalsa,[FajitaVegetables,Pinto...$11.2518341ChickenSaladBowl[FreshTomatoSalsa,[FajitaVegetables,Lettu...$8.7518341ChickenSaladBowl[FreshTomatoSalsa,[FajitaVegetables,Pinto...$8.75輸出結(jié)果表1.1.18總價(jià)最高的10個(gè)訂單訂單id數(shù)量名稱描述單價(jià)總價(jià)144315ChipsandFreshTomatoSalsaNaN44.25663.75166010BottledWaterNaN15.00150.005114ChickenBurrito[FreshTomatoSalsa,[FajitaVegetables,Rice,...35.00140.0014434ChickenBurrito[FreshTomatoSalsa,[Rice,BlackBeans,Chees...35.00140.0015598SideofChipsNaN13.52108.1613983CarnitasBowl[RoastedChiliCornSalsa,[FajitaVegetables,...35.25105.7514433VeggieBurrito[FreshTomatoSalsa,[FajitaVegetables,Rice,...33.75101.251783ChickenBowl[[FreshTomatoSalsa(Mild),Tomatillo-GreenC...32.9498.825113SteakBurrito[FreshTomatoSalsa,[FajitaVegetables,Rice,...27.7583.2514433SteakBurrito[FreshTomatoSalsa,[Rice,BlackBeans,Chees...27.7583.25題前思考問題描述問題解答怎樣讀取csv文件中的數(shù)據(jù)?read_csv()函數(shù)

怎樣轉(zhuǎn)換“單價(jià)”數(shù)據(jù)的類型?使用astype()函數(shù)強(qiáng)制轉(zhuǎn)換成浮點(diǎn)型

如何計(jì)算總價(jià)?利用“單價(jià)“和”數(shù)量“計(jì)算各訂單的總價(jià)

怎樣取總價(jià)最高的前10個(gè)訂單?用sort_values()方法對”總價(jià)“進(jìn)行排序,用head()方法取數(shù)據(jù)表中的前10行數(shù)據(jù)

importpandasaspd

importnumpyasnpdata=pd.read_csv(r"D:\pydata\項(xiàng)目一\訂單數(shù)據(jù)表.csv",encoding='gbk')①data["單價(jià)"]=data["單價(jià)"].str[1:].astype(float)②data['總價(jià)']=data["單價(jià)"]*data['數(shù)量']③data.sort_values(by='總價(jià)',ascending=False,inplace=True)④data=data.head(10)⑤

print(data)

程序代碼使用read_csv()函數(shù)讀取csv文件中的數(shù)據(jù)。參數(shù)encoding='gbk'表示編碼方式為'gbk'。訂單id數(shù)量名稱描述單價(jià)11ChipsandFreshTomatoSalsaNaN$2.3911Izze[Clementine]$3.3911NantucketNectar[Apple]$3.3911ChipsandTomatillo-GreenChiliSalsaNaN$2.3922ChickenBowl[Tomatillo-RedChiliSalsa(Hot),[BlackBeans...$16.98...............18331SteakBurrito[FreshTomatoSalsa,[Rice,BlackBeans,Sour...$11.7518331SteakBurrito[FreshTomatoSalsa,[Rice,SourCream,Cheese...$11.7518341ChickenSaladBowl[FreshTomatoSalsa,[FajitaVegetables,Pinto...$11.2518341ChickenSaladBowl[FreshTomatoSalsa,[FajitaVegetables,Lettu...$8.7518341ChickenSaladBowl[FreshTomatoSalsa,[FajitaVegetables,Pinto...$8.75importpandasaspd

importnumpyasnpdata=pd.read_csv(r"D:\pydata\項(xiàng)目一\訂單數(shù)據(jù)表.csv",encoding='gbk')①data["單價(jià)"]=data["單價(jià)"].str[1:].astype(float)②data['總價(jià)']=data["單價(jià)"]*data['數(shù)量']③data.sort_values(by='總價(jià)',ascending=False,inplace=True)④data=data.head(10)⑤

print(data)

程序代碼將數(shù)據(jù)框中的“單價(jià)”列轉(zhuǎn)換為實(shí)型。用str屬性的切片str[1:]取字符串從1開始到最后一個(gè)字符的子串,相當(dāng)于去掉“$”符號。

訂單id數(shù)量名稱描述單價(jià)011ChipsandFreshTomatoSalsaNaN2.39111Izze[Clementine]3.39211NantucketNectar[Apple]3.39311ChipsandTomatillo-GreenChiliSalsaNaN2.39422ChickenBowl[Tomatillo-RedChiliSalsa(Hot),[BlackBeans...16.98..................461718331SteakBurrito[FreshTomatoSalsa,[Rice,BlackBeans,Sour...11.75461818331SteakBurrito[FreshTomatoSalsa,[Rice,SourCream,Cheese...11.75461918341ChickenSaladBowl[FreshTomatoSalsa,[FajitaVegetables,Pinto...11.25462018341ChickenSaladBowl[FreshTomatoSalsa,[FajitaVegetables,Lettu...8.75462118341ChickenSaladBowl[FreshTomatoSalsa,[FajitaVegetables,Pinto...8.75importpandasaspd

importnumpyasnpdata=pd.read_csv(r"D:\pydata\項(xiàng)目一\訂單數(shù)據(jù)表.csv",encoding='gbk')①data["單價(jià)"]=data["單價(jià)"].str[1:].astype(float)②data['總價(jià)']=data["單價(jià)"]*data['數(shù)量']③data.sort_values(by='總價(jià)',ascending=False,inplace=True)④data=data.head(10)⑤

print(data)

程序代碼計(jì)算“單價(jià)”列和“數(shù)量”列的乘積,兩個(gè)序列相乘的結(jié)果,就是兩個(gè)序列對應(yīng)數(shù)值相乘的積構(gòu)成的新的序列。通過賦值,將這個(gè)序列以“總價(jià)”為列名添加到數(shù)據(jù)框的最后一列之后。

訂單id數(shù)量名稱描述單價(jià)總價(jià)11ChipsandFreshTomatoSalsaNaN2.392.3911Izze[Clementine]3.393.3911NantucketNectar[Apple]3.393.3911ChipsandTomatillo-GreenChiliSalsaNaN2.392.3922ChickenBowl[Tomatillo-RedChiliSalsa(Hot),[BlackBeans...16.9833.96..................18331SteakBurrito[FreshTomatoSalsa,[Rice,BlackBeans,Sour...11.7511.7518331SteakBurrito[FreshTomatoSalsa,[Rice,SourCream,Cheese...11.7511.7518341ChickenSaladBowl[FreshTomatoSalsa,[FajitaVegetables,Pinto...11.2511.2518341ChickenSaladBowl[FreshTomatoSalsa,[FajitaVegetables,Lettu...8.758.7518341ChickenSaladBowl[FreshTomatoSalsa,[FajitaVegetables,Pinto...8.758.75importpandasaspd

importnumpyasnpdata=pd.read_csv(r"D:\pydata\項(xiàng)目一\訂單數(shù)據(jù)表.csv",encoding='gbk')①data["單價(jià)"]=data["單價(jià)"].str[1:].astype(float)②data['總價(jià)']=data["單價(jià)"]*data['數(shù)量']③data.sort_values(by='總價(jià)',ascending=False,inplace=True)④data=data.head(10)⑤

print(data)

程序代碼使用sort_values進(jìn)行排序,其中by指定按照“總價(jià)”排序,ascending=False為降序排序,inplace=True表示會(huì)修改原數(shù)據(jù)。

訂單id數(shù)量名稱描述單價(jià)總價(jià)144315ChipsandFreshTomatoSalsaNaN44.25663.75166010BottledWaterNaN15.00150.005114ChickenBurrito[FreshTomatoSalsa,[FajitaVegetables,Rice,...35.00140.0014434ChickenBurrito[FreshTomatoSalsa,[Rice,BlackBeans,Chees...35.00140.0015598SideofChipsNaN13.52108.16..................471CannedSoda[Dr.Pepper]1.091.09871CannedSoda[CocaCola]1.091.091881CannedSoda[CocaCola]1.091.0911171CannedSoda[DietDr.Pepper]1.091.0916291BottledWaterNaN1.091.09importpandasaspd

importnumpyasnpdata=pd.read_csv(r"D:\pydata\項(xiàng)目一\訂單數(shù)據(jù)表.csv",encoding='gbk')①data["單價(jià)"]=data["單價(jià)"].str[1:].astype(float)②data['總價(jià)']=data["單價(jià)"]*data['數(shù)量']③data.sort_values(by='總價(jià)',ascending=False,inplace=True)④data=data.head(10)⑤

print(data)

程序代碼data.head(10)表示取數(shù)據(jù)表中的前10行數(shù)據(jù)。

訂單id數(shù)量名稱描述單價(jià)總價(jià)144315ChipsandFreshTomatoSalsaNaN44.25663.75166010BottledWaterNaN15.00150.005114ChickenBurrito[FreshTomatoSalsa,[FajitaVegetables,Rice,...35.00140.0014434ChickenBurrito[FreshTomatoSalsa,[Rice,BlackBeans,Chees...35.00140.0015598SideofChipsNaN13.52108.1613983CarnitasBowl[RoastedChiliCornSalsa,[FajitaVegetables,...35.25105.7514433VeggieBurrito[FreshTomatoSalsa,[FajitaVegetables,Rice,...33.75101.251783ChickenBowl[[FreshTomatoSalsa(Mild),Tomatillo-GreenC...32.9498.825113SteakBurrito[FreshTomatoSalsa,[FajitaVegetables,Rice,...27.7583.2514433SteakBurrito[FreshTomatoSalsa,[Rice,BlackBeans,Chees...27.7583.25任務(wù)小結(jié)1.通過read_csv()函數(shù)讀取csv文件;2.使用astype()函數(shù)將字符串類型強(qiáng)制轉(zhuǎn)換成浮點(diǎn)型;3.用sort_values()方法進(jìn)行排序;4.用head()方法取數(shù)據(jù)表中的前幾行數(shù)據(jù)。一展身手在“訂單數(shù)據(jù)表”中,按總價(jià)升序排序后,取訂單最后十個(gè)數(shù)據(jù)。結(jié)果如表1.1.23所示。表

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論