C'est facile à oublier, alors prends note
import pandas as pd
data = [
{"name": "Taro Tanaka", "organization": "Example1", "age": 18},
{"name": "Hanako Yamada", "organization": "Example1", "age": 20},
{"name": "Ichiro Suzuki", "organization": "Example2", "age": 33},
{"name": "Michiko Sato", "organization": "Example2", "age": 50},
...
]
#Méthode orthodoxe
arr = [
r for r in data
if r["organization"] == "Example1" and r["age"] > 18
]
## sort
sorted_arr = sorted(arr, key=lambda x: x["age"])
#Utilisez des pandas
df = pd.DataFrame(data)
arr2 = df[(df["organization"] == "Example2") & (df["age"] > 18)]
## sort
sorted_arr = df[(df["organization"] == "Example2") & (df["age"] > 18)].sort_values('age')
Recommended Posts