忘れがちなのでメモ
コード
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},
...
]
# オーソドックスな方法
arr = [
r for r in data
if r["organization"] == "Example1" and r["age"] > 18
]
## sort
sorted_arr = sorted(arr, key=lambda x: x["age"])
# 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')