




版權(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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 教育與科技的融合未來趨勢探討
- 農(nóng)村體育賽事發(fā)展創(chuàng)新創(chuàng)業(yè)項(xiàng)目商業(yè)計(jì)劃書
- 接入網(wǎng)設(shè)備創(chuàng)新創(chuàng)業(yè)項(xiàng)目商業(yè)計(jì)劃書
- 生態(tài)寵物食品創(chuàng)新創(chuàng)業(yè)項(xiàng)目商業(yè)計(jì)劃書
- 2024-2025學(xué)年河南省洛陽洛寧縣聯(lián)考數(shù)學(xué)九年級第一學(xué)期期末學(xué)業(yè)質(zhì)量監(jiān)測模擬試題含解析
- 錦州醫(yī)科大學(xué)《感覺統(tǒng)合訓(xùn)練》2023-2024學(xué)年第一學(xué)期期末試卷
- 2025版特色小鎮(zhèn)場攤位租賃經(jīng)營合同模板
- 二零二五年度ISO9000質(zhì)量認(rèn)證及企業(yè)內(nèi)訓(xùn)一體化服務(wù)合同
- 2025版智能家居安防系統(tǒng)安裝承包合同
- 二零二五年度別墅自建房施工合同施工項(xiàng)目進(jìn)度調(diào)整與索賠管理
- 個(gè)別化教育計(jì)劃(IEP)模板
- 污水處理工藝培訓(xùn)課件
- 2024-2030年中國抗菌陶瓷市場經(jīng)營效益與供需前景預(yù)測報(bào)告
- 礦山開采土方外運(yùn)施工方案
- 礦泉水買賣合同樣本
- 第二章有理數(shù)及其運(yùn)算總結(jié)專練2023-2024學(xué)年魯教版(五四制)數(shù)學(xué)六年級上冊
- 2024汽車租賃合同協(xié)議可打印
- 光伏電站施工管理要點(diǎn)培訓(xùn)
- 2024上海紡織工業(yè)職工大學(xué)教師招聘考試筆試試題
- 2024年家庭教育指導(dǎo)師考試(重點(diǎn))題庫及答案(含各題型)
- GB/T 14048.11-2024低壓開關(guān)設(shè)備和控制設(shè)備第6-1部分:多功能電器轉(zhuǎn)換開關(guān)電器
評論
0/150
提交評論