Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的 DataFrame 有两列,两列都有 NaN 值。我需要删除列 user_email 上带有 NaN 的行。
但是,我使用df['user_email'] = df['user_email'].dropna()了但它返回了完全相同的 DataFrame,第二列上的所有 NaN 值都完好无损。
df['user_email'] = df['user_email'].dropna()
如何删除第二列上带有 NaN 的行?
您可以使用布尔索引。这允许您根据条件语句选择行(例如,df.user_email.notna())
df.user_email.notna()
df = df[df.user_email.notna()]
您可以使用subset关键字参数。
subset
df = df.dropna(subset=['user_email'])
您可能需要就地=True:
df.dropna(subset=['user_email'], inplace=True)