本篇笔记为原书第五章节的内容。
- Flitering a DataFrame
DataFrame数据优化(内存优化)
主要就是对一些数据类型进行变换,如
- 字符串转为布尔型
- 类别型转为数字型
- 缺失值处理再类型转换等
- 浮点型数值转为整数型
单条件获取数据
==.png!= / >.png
多条件提取数据
逻辑条件We can filter a DataFrame with multiple conditions by creating two independent Boolean Series and then declaring the logical criterion that pandas should apply between them.
条件过滤
-
isin()
isin() -
between()
between()
between() -
isnull() # 某列中各个值是否为空
-
notnull()
-
dropna() # 丢弃掉空值,how参数(all, any),subset参数(指定某列),thresh参数(阈值,几个空值)
dropna()
重复值操作
- df['col'].duplicated() # col列中各个值是否为重复值,keep参数(first,last)重复值首次(最后)出现为真,其他地方出现为假
-
drop_duplicates() # 去重,subset参数(指定列),keep参数(first,last)
drop_duplicates()
网友评论