【发布时间】:2017-01-02 17:12:34
【问题描述】:
我有一个这样的数据框,
a b c d e
1 0 0 4 5
0 23 5 0 0
0 5 8 6 0
现在,我像这样在整个数据框上使用np.log。
df = (np.log(weights_df))
一切都很好,并且正在锻炼。但是,无论哪里有 0,它都应该给出“-inf”。我想把所有这些都转换成别的东西,也许用“0”代替“-inf”。我试过fillna,但我认为它不会在这里工作。
我该怎么做?
【问题讨论】:
-
您需要设置
pd.set_option('use_inf_as_null', True)以使inf 被视为NaN。然后,您也可以使用fillna或dropna作为 inf 值。
标签: python-2.7 pandas numpy dataframe