我有以下列表构成一个dict,包含来自interwebz的一些数据:
names = ['Progressor GTI + RS10 PR 17/18, alpinski, unisex', 'Alpine Skis The Curv DTX 16/17, alpinski, carving', 'Alpine Skis Dobermann Spitfire Ti 16/17, alpinski', 'Redster G7 + X12 17/18, alpinski, unisex', 'Redster S7 + XT12 17/18, alpinski, unisex', 'Redster WT + Binding 17/18, carvingski, unisex', 'PRO MTN 77 + MBS 10PR 17/18, alpinski, unisex', 'Hero Elite HP NX 12 Konect WTR B80 17/18, carvingski, unisex', 'All Mountain Skis Pinnacle 95 15/16, frikjøringsski', 'Alpine Skis Progressor F17 16/17, alpinski, carving', 'Alpine Skis Pro Mtn 77 16/17, alpinski, all mountain', 'Twintip Skis Domain 17/18, alpinski, jib/park', 'Cloud 9 Woman + Litium 10 17/18, alpinski, dame', 'Redster GT + Lithium 10 17/18, carvingski, unisex', 'Alpine Skis Aspire W 17/18 , alpinski, carving, dame', 'Alpine Skis Speed Zone 7 Express 11 16/17, alpinski', 'Hero Elite All Turn XPRESS 11 B83 17/18, alpinski', 'Balanze Woman + Litium 10 17/18, alpinski, dame', 'Alpine Skis Cloud Nine W Lith 10 , alpinski, dame, all mountain', 'Passion PRO/Xpress 10 Woman B83 17/18, carvingski, dame', 'Avenger 75 m/Adv Pro binding', 'Alpine Skis NRGY 85 (flat) 16/17, alpinski', 'Alpine Skis GT 74 Adv Evo 17/18, alpinski', 'Alpine Skis Sentra S2 Pro Evo 17/18, alpinski, dame', 'Twintip Skis Sight 17/18, parkski', 'Alpine Skis Zenith Xpress B83 16/17, alpinski', 'Alpine Skis Intense 6 W 16/17, alpinski, dame', 'Zenith PRO/Xpress 10 B83 17/18, carvingski', 'Performer XT Fibre + Lithium AW 17/18, alpinski, unisex', 'Alpine Skis Performer Lithium Usx 16/17, bakkeski', 'Team Jr 4.5 binding 100-120 17/18, carvingski, barn/junior', 'Alpine Skis Vantage Jr III XTE7 17/18, bakkeski, junior', 'PCarv Kids Blue 17/18, alpinski, barn/junior', 'PCarv Kids Pink 17/18, alpinski, barn/junior', 'Alpine Skis Team Jr 7.0 binding 16/17, alpinski med binding, junior', 'Redster Jr J2 130-150 + L7 ET 17/18, alpinski, junior', 'Alpine Skis Team Jr m/7.0 15/16, alpinski, junior', 'PCarv Mini Blue 17/18, alpinski, barn', 'Powah Jib By Rossignol, alpinski for barn', 'Starlett Alpinski Jente']
brands = ['Fischer', 'Fischer', 'Nordica', 'Atomic', 'Atomic', 'Atomic', 'Fischer', 'Rossignol', 'K2', 'Fischer', 'Fischer', 'K2', 'Atomic', 'Atomic', 'Fischer', 'Dynastar', 'Rossignol', 'Atomic', 'Atomic', 'Rossignol', 'Nordica', 'Nordica', 'Nordica', 'Nordica', 'K2', 'Rossignol', 'Dynastar', 'Rossignol', 'Atomic', 'Atomic', 'Nordica', 'Atomic', 'Rossignol', 'Rossignol', 'Nordica', 'Atomic', 'Nordica', 'Rossignol', 'Rossignol', 'Dynastar']
prices = ['6\xa0499', '5\xa0000', '5\xa0000', '5\xa0000', '5\xa0000', '4\xa0000', '3\xa0500', '3\xa0500', '3\xa0000', '3\xa0000', '3\xa0000', '3\xa0000', '3\xa0000', '3\xa0000', '2\xa0500', '2\xa0500', '2\xa0500', '2\xa0500', '2\xa0500', '2\xa0499', '2\xa0000', '2\xa0000', '2\xa0000', '2\xa0000', '2\xa0000', '2\xa0000', '2\xa0000', '2\xa0000', '2\xa0000', '1\xa0500', '1\xa0500', '1\xa0400', '1\xa0299', '1\xa0299', '1\xa0200', '1\xa0200', '1\xa0200', '999', '800', '600']
avail_sizes = ['160, 167', '171', '162, 168, 174', '168, 175, 182', '156, 163, 170', '165', '164, 171', '161, 166, 171', '184', '167, 174', '171, 178', '159, 169', '150', '162', '150, 160', '167', '163', '162', '163', '157, 165', '160, 168', '177, 185', '160, 168, 176', '144, 152, 160, 168', '149', '165', '158', '165, 173', '156, 163, 170', '170', '100, 110, 120', '130, 140', '130 cm', '100 cm, 110 CM, 120 cm, 130 cm', '130', '130', '120', '70 cm, 92 cm', '125', '130']
carving_skis = {"Product": names,
"Brand": brands,
"Price": prices,
"Available sizes": avail_sizes}
我想做的是"过滤"当我打印它(使用pandas数据帧)时这个词典,这样我只提取某个品牌的产品。让我们说我只想看Atomic雕刻滑雪板,我怎么能打印一张只显示原子滑雪板产品信息的表格(包括品牌本身,即使它对所有行都是相同的)?
答案 0 :(得分:3)
因为你想要使用pandas,这应该是非常方便的:
import pandas as pd
df=pd.DataFrame(carving_skis)
new=df[df["Brand"]=="Atomic"]
答案 1 :(得分:2)
首先,我会将这些数组转换为单独的产品描述数组,如下所示:
dynastar = [ski for ski in carving_skis if ski["Brand"]=="Dynastar"]
然后我会从那里选出元素,例如获得Brand ==“Dynastar”的所有产品:
{{1}}