1. # SQL中
  2. select * from table where column_name = some_value;

iloc 和 loc 的区别

  1. loc 是基于索引值的,切片是左闭右闭的
  2. 常用:iloc 是基于位置的,切片是左闭右开的

pandas中

布尔索引

image.png

位置索引

image.png

标签索引(需要知道标签值,与iloc不同)

image.png

使用API(pd.DataFrame.query()方法数据量大的时候,效率比常规的方法更高效。)

  • image.png

筛选某个值在某个范围可用isin

df.loc[df[‘column_name’].isin(some_values)]

最大最小值筛选

# 从大到小排序,并取得 'Math' 列最大的 3 行
print(df.nlargest(3,'Math')) # 从大到小排序,并取得 'Math' 最大的 3 行
# 从小到大排序,并取得 'Math' 列最小的 3 行
print(df.nsmallest(3,'Math')) # 从大到小排序,并取得 'Math' 最大的 3 行