Es ist leicht zu vergessen, machen Sie sich also eine Notiz
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},
...
]
#Orthodoxe Methode
arr = [
r for r in data
if r["organization"] == "Example1" and r["age"] > 18
]
## sort
sorted_arr = sorted(arr, key=lambda x: x["age"])
#Verwenden Sie 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