程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[pandas tip] delete the row whose specified column value is empty

編輯:Python
Enjoy the beautiful picture 2022/06/28

In recent development requirements , This involves deleting rows with empty values in the specified columns , Access to information , Use .dropna Can meet the above requirements , To this end, I specially wrote this article for future review and learning

Missing values delete df.dropna()https://blog.csdn.net/Hudas/article/details/122924791 Data preparation

import pandas as pd
import numpy as np
df = pd.DataFrame([['liver',np.nan,89,21,24,64],
['Arry','C',36,37,37,57],
[np.nan,np.nan,57,60,18,84],
['Eorge','C',93,96,71,np.nan],
[None,None,65,49,61,86]
],
columns = ['name','team','Q1','Q2','Q3','Q4'])

df

From the above df The data sheet shows that , All in all 6 Null value at  

problem : Delete name,team Rows with empty values in two column fields

df = df.dropna(subset=['name','team'])

df( First processing ) 

After the first treatment df Data sheet , You can see Eorge In that line of record Q4 Still empty (nan) , If you want to delete Q4 Empty record , The following operations can be carried out

df = df.dropna(subset=['name','team','Q4'])

df( Second treatment )


Extended supplementary information

Filter and delete the row where the target value is located https://blog.csdn.net/Hudas/article/details/125394010?spm=1001.2014.3001.5501

Screening DataFrame Data rows with null values https://blog.csdn.net/Hudas/article/details/125351275?spm=1001.2014.3001.5501


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved