赞
踩
def filterFun(): """ 过滤数据 :return: """ data = [ [11, 12, 13, 14], [21, 22, 23, 24], [31, 32, 33, 34], [41, 42, 43, 44], [51, 52, 53, 54] ] columns = ['col-1', 'col-2', 'col-3', 'col-4'] index = ['idx-1', 'idx-2', 'idx-3', 'idx-4', 'idx-5'] df = pd.DataFrame(data=data, index=index, columns=columns) # 过滤单列 filter_1 = df.loc[(df["col-1"] > 31)] print(filter_1) # 过滤多列 filter_2 = df.loc[(df["col-1"] > 31) & (df["col-3"] >= 43)] print(filter_2)
原始数据 返回结果:
col-1 col-2 col-3 col-4
idx-1 11 12 13 14
idx-2 21 22 23 24
idx-3 31 32 33 34
idx-4 41 42 43 44
idx-5 51 52 53 54
filter_1 返回结果:
filter_2 返回结果:
col-1 col-2 col-3 col-4
idx-4 41 42 43 44
idx-5 51 52 53 54
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。