相关疑难解决方法(0)

调用resample后如何使用值0填充()?

要么我不理解文档或它已过时.

如果我跑

user[["DOC_ACC_DT", "USER_SIGNON_ID"]].groupby("DOC_ACC_DT").agg(["count"]).resample("1D").fillna(value=0, method="ffill")
Run Code Online (Sandbox Code Playgroud)

它得到了

TypeError: fillna() got an unexpected keyword argument 'value'
Run Code Online (Sandbox Code Playgroud)

如果我跑

.fillna(0)
Run Code Online (Sandbox Code Playgroud)

我明白了

ValueError: Invalid fill method. Expecting pad (ffill), backfill (bfill) or nearest. Got 0
Run Code Online (Sandbox Code Playgroud)

如果我然后设置

.fillna(0, method="ffill") 
Run Code Online (Sandbox Code Playgroud)

我明白了

TypeError: fillna() got multiple values for keyword argument 'method'
Run Code Online (Sandbox Code Playgroud)

所以唯一有效的是

.fillna("ffill")
Run Code Online (Sandbox Code Playgroud)

但当然这只是一个向前填补.但是,我想NaN用零替换.我在这做错了什么?

python pandas

12
推荐指数
2
解决办法
6381
查看次数

标签 统计

pandas ×1

python ×1