dropping infinite values from dataframes in pandas?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: what is the quickest/simplest way to drop nan and inf/-inf values from a pandas DataFrame without resetting mode.use_inf_as_null ? I'd like to be able to use the subset and how arguments of dropna , except with inf values considered missing, like: df.dropna(subset=["col1", "col2"], how="all", with_inf=True) is this possible? Is there a way to tell dropna to include inf in its definition of missing values? 回答1: The simplest way would be to first replace infs to NaN: df.replace([np.inf, -np.inf], np.nan) and then use the dropna : df.replace(