📜  pandas 过滤值范围 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:51.039000             🧑  作者: Mango

代码示例1
import pandas as pd

#initialize dataframe
df = pd.DataFrame({'a': [2, 4, 8, 5], 'b': [2, 0, 9, 7]})

#check if the values of df['a'] are in the range(3,6)
out = df['a'].isin(range(3,6))

#filter dataframe
filtered_df = df[out]

print('Original DataFrame\n-------------------\n',df)
print('\nFiltered DataFrame\n-------------------\n',filtered_df)