Pandas测试Excel文件:fillna()与strip()相互作用的影响

遇见的问题

np.nan被strip之后仍为nan,但是此nan无法被.fillna()处理,处理后仍然为nan

    get_address_local_mail['CountryID_mail'] = get_address_local_mail['CountryID_mail'].apply(lambda x: np.nan if x == "00000000-0000-0000-0000-000000000000" or x == "NULL" else x) 
    get_address_local_mail['CountryID_local'] = get_address_local_mail['CountryID_local'].apply(lambda x: np.nan if x == "00000000-0000-0000-0000-000000000000" or x == "NULL" else x) 
    for column in get_address_local_mail.columns:  
        get_address_local_mail[column] = get_address_local_mail[column].astype(str).str.strip()
    get_address_local_mail = get_address_local_mail.fillna('')

 此时打印结果仍然是nan.

影响后续结果判断

先fillna()后试一下,显示结果中不再显示nan 

posted @ 2024-10-10 17:23  蜗牛果果  阅读(2)  评论(0编辑  收藏  举报