Filtrer valeurs Dataframe
Bonjour,
Je souhaite ajouter plusieurs lignes à un DataFrame en choisissant les lignes spécifiques à ajouter. Voici le code que j'utilise:
Code:
1 2 3 4 5 6 7
|
def hint_mapping(dict_):
for k, v in dict_.items():
wanted = "on the way"
return {j for i, j in v.items() if wanted in j}
hints_dataframe=hints_dataframe.append({'Hints': hint_mapping(json_data['gossip_stones'])},ignore_index=True) |
Grâce à la fonction hint_mapping, je souhaiterais seulement garder les lignes qui contiennent "on the way". Cependant j'obtient un résultat bizarre. J'obtient certaines lignes de mon DataFrame vides (avec juste set() ) et mon DataFrame s'arrête à 10'000 lignes, 10'000 étant le nombre de fichiers json et donc de dictionnaire "gossip_stones" sur lesquels j'effectue ma fonction. Or, pour chaque dictionnaire "gossip_stones", il y a plusieurs éléments avec le string "on the way", je devrais donc avoir plusieurs lignes pour chaque dictionnaire "gossip_stones", et donc plus de 10'000 lignes (et pas de lignes vides non plus). Comment ça se fait?
Voici à quoi ressemble le dictionnaire gossip_stones. C'est en fait un dictionnaire qui contient plusieurs dictionnaires.
"gossip_stones": {
"Colossus (Spirit Temple)": {"text": "They say that the #Skull Mask# yields #Ruto's Letter#.", "colors": ["Green", "Red"]},
"DMC (Bombable Wall)": {"text": "They say that #Deku Tree# is on the way of the hero.", "colors": ["Light Blue"]},
"DMC (Upper Grotto)": {"text": "They say that Zelda is a poor leader."},
"DMT (Biggoron)": {"text": "They say that the final reward from the #Frogs of Zora's River# is #a Piece of Heart#.", "colors": ["Green", "Red"]},
"DMT (Storms Grotto)": {"text": "They say that Lon Lon Ranch prospered under Ingo."},
"Dodongos Cavern (Bombable Wall)": {"text": "They say that #Kakariko Village# is on the way of the hero.", "colors": ["Light Blue"]},
"GC (Maze)": {"text": "They say that #Sacred Forest Meadow# is on the way of the hero.", "colors": ["Light Blue"]},
"GC (Medigoron)": {"text": "They say that #Ganon's Castle# is on the way of the hero.", "colors": ["Light Blue"]},
"GV (Waterfall)": {"text": "They say that a hero ventures #beyond the wasteland# to learn #Epona's Song#.", "colors": ["Green", "Red"]},
"Graveyard (Shadow Temple)": {"text": "They say that #Ganon's Castle# is on the way of the hero.", "colors": ["Light Blue"]},
"HC (Malon)": {"text": "They say that the #Flare Dancer atop the Fire Temple# guards a chest containing #a Blue Rupee#.", "colors": ["Green", "Red"]},
"HC (Rock Wall)": {"text": "They say that slaying #30 Gold Skulltulas# reveals #Bombchus (10 pieces)#.", "colors": ["Green", "Red"]},
"HC (Storms Grotto)": {"text": "Save your future, end the Happy Mask Salesman."},
"HF (Cow Grotto)": {"text": "They say that you're wasting time reading this hint, but I disagree. Talk to me again!"},
"HF (Near Market Grotto)": {"text": "You're playing a Randomizer. I'm randomized!^Here's a random number: #4#.&Enjoy your Randomizer!"},
"HF (Open Grotto)": {"text": "I'm stoned. Get it?"},
"HF (Southeast Grotto)": {"text": "Mweep.^Mweep.^Mweep.^Mweep.^Mweep.^Mweep.^Mweep.^Mweep.^Mweep.^Mweep.^Mweep.^Mweep."},
"KF (Deku Tree Left)": {"text": "They say that the #Skull Mask# yields #Ruto's Letter#.", "colors": ["Green", "Red"]},
"KF (Deku Tree Right)": {"text": "They say that slaying #50 Gold Skulltulas# reveals #Arrows (30 pieces)#.", "colors": ["Green", "Red"]},
"KF (Outside Storms)": {"text": "They say that #Sacred Forest Meadow# is on the way of the hero.", "colors": ["Light Blue"]},
"KF (Storms Grotto)": {"text": "Open your eyes.^Open your eyes.^Wake up, @."},
"Kak (Open Grotto)": {"text": "You're comparing yourself to me?^Ha! You're not even good enough to be my fake."},
"LH (Lab)": {"text": "They say that slaying #40 Gold Skulltulas# reveals #a Blue Rupee#.", "colors": ["Green", "Red"]},
"LH (Southeast Corner)": {"text": "They say that #flames in the Composers' Grave# reveal #a Recovery Heart#.", "colors": ["Green", "Red"]},
"LH (Southwest Corner)": {"text": "They say that #Biggoron# crafts #a Recovery Heart#.", "colors": ["Green", "Red"]},
"LW (Bridge)": {"text": "They say that slaying #40 Gold Skulltulas# reveals #a Blue Rupee#.", "colors": ["Green", "Red"]},
"LW (Near Shortcuts Grotto)": {"text": "They say Ganondorf's bolts can be reflected with glass or steel."},
"SFM (Maze Lower)": {"text": "They say that the final reward from the #Frogs of Zora's River# is #a Piece of Heart#.", "colors": ["Green", "Red"]},
"SFM (Maze Upper)": {"text": "They say that the #frozen cavern# echoes with #the Prelude of Light#.", "colors": ["Green", "Red"]},
"SFM (Saria)": {"text": "They say that the #Ocarina of Time# teaches #the Nocturne of Shadow#.", "colors": ["Green", "Red"]},
"ToT (Left)": {"text": "They say that #Kakariko Village# is on the way of the hero.", "colors": ["Light Blue"]},
"ToT (Left-Center)": {"text": "They say that #Kakariko Village# is on the way of the hero.", "colors": ["Light Blue"]},
"ToT (Right)": {"text": "They say that #Kakariko Village# is on the way of the hero.", "colors": ["Light Blue"]},
"ToT (Right-Center)": {"text": "They say that #Kakariko Village# is on the way of the hero.", "colors": ["Light Blue"]},
"ZD (Mweep)": {"text": "They say that slaying #50 Gold Skulltulas# reveals #Arrows (30 pieces)#.", "colors": ["Green", "Red"]},
"ZF (Fairy)": {"text": "They say that the #Ocarina of Time# teaches #the Nocturne of Shadow#.", "colors": ["Green", "Red"]},
"ZF (Jabu)": {"text": "They say that #Deku Tree# is on the way of the hero.", "colors": ["Light Blue"]},
"ZR (Near Domain)": {"text": "They say that #Biggoron# crafts #a Recovery Heart#.", "colors": ["Green", "Red"]},
"ZR (Near Grottos)": {"text": "They say that slaying #30 Gold Skulltulas# reveals #Bombchus (10 pieces)#.", "colors": ["Green", "Red"]},
"ZR (Open Grotto)": {"text": "You found a spiritual Stone! By which I mean, I worship Nayru."}
Voilà j'espère que c'est clair je ne sais pas si j'ai bien expliqué le problème, merci d'avance.