M P*_*AUL 3 numpy dataframe python-2.7 pandas
我有一个这样的数据框,
a b c d e
1 0 0 4 5
0 23 5 0 0
0 5 8 6 0
Run Code Online (Sandbox Code Playgroud)
现在,我np.log
像这样在整个数据框上使用 a 。
df = (np.log(weights_df))
Run Code Online (Sandbox Code Playgroud)
一切都很好,正在锻炼。但是只要有 0,它就会按照预期给出“-inf”。我想将所有这些转换为其他内容,也许是“0”代替“-inf”。我试过了,fillna
但我不认为它会在这里工作。
我该怎么做?
-np.inf
并且np.inf
不被视为 null 或 na。
使用replace(-np.inf, 0)
:
df = (np.log(weights_df)).replace(-np.inf, 0)
df
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4858 次 |
最近记录: |