列表数据筛选
nums = [1, 3, 6, 8, 2, 9, 4]
result = [num for num in nums if num > 5]
print(result)
字典数据筛选
people = {
"Alice": 22,
"Bob": 28,
"Charlie": 20,
"David": 30
}
filtered_people = {name: age for name, age in people.items() if age > 25}
print(filtered_people)
pandas数据筛选
import pandas as pd
data = {
"Name": ["Alice", "Bob", "Charlie", "David"],
"Math": [78, 85, 90, 70],
"English": [88, 76, 82, 92]
}
df = pd.DataFrame(data)
filtered_df = df[df["Math"] > 80]
print(filtered_df)