Skip to main content
 首页 » 编程设计

python之排除具有空单元格的行

2024年12月31日9mq0036

我试图排除没有“UID”的行。 我试过了

temp = pd.read_csv(link) 
temp = temp[temp['UID'].notnull()] 

它没有用。我又试了一次,

temp = temp[temp['UID']!='null'] 

也没用。

这是 jupyter notebook 形式的输出。

screenshot of the output

请您参考如下方法:

有问题 nan 是字符串,所以可能的解决方案是:

temp = temp[temp['UID']!='nan'] 

或者:

temp = temp.replace('nan', np.nan) 
temp = temp[temp['UID'].notnull()] 

类似的:

temp = temp.dropna(subset=['UID'])