# SQL中
select * from table where column_name = some_value;
iloc 和 loc 的区别
- loc 是基于索引值的,切片是左闭右闭的
- 常用:iloc 是基于位置的,切片是左闭右开的
布尔索引
位置索引
标签索引(需要知道标签值,与iloc不同)
使用API(pd.DataFrame.query()方法数据量大的时候,效率比常规的方法更高效。)
筛选某个值在某个范围可用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 行