删除含有缺失值的行df
时间: 2024-01-06 12:05:12 浏览: 82
要删除含有缺失值的行df,可以使用df.dropna()方法。这个方法会删除所有含有缺失值的行。具体操作如下所示:
```python
import pandas as pd
# 原数据
df = pd.DataFrame({'A':\['a1','a1','a2','a2'\], 'B':\['b1','b2',None,'b2'\], 'C':\[1,2,3,4\], 'D':\[5,6,None,8\], 'E':\[5,None,7,8\] })
# 删除含有缺失值的行
df.dropna(inplace=True)
```
这样就会删除df中所有含有缺失值的行。
#### 引用[.reference_title]
- *1* *3* [[Pandas] 缺失值删除 df.dropna()](https://blog.csdn.net/Hudas/article/details/122924791)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [删除df中值为指定值的行](https://blog.csdn.net/guotianqing/article/details/123359894)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文