【发布时间】:2021-04-19 02:14:45
【问题描述】:
代码
df=pd.DataFrame({'Col1':[1, '-','-'], 'Col2':['-','-',2]})
df.sum()
返回
Series([], dtype: float64)
假设字符串可能会造成困难,但这也不起作用:
df.sum(numeric_only=True)
返回
Series([], dtype: float64)
我不明白输出试图告诉我什么以及为什么我首先得到它。
只有当我用零替换字符串时,结果才符合预期:
df.replace('-',0).sum()
返回
Col1 1
Col2 2
dtype: int64
【问题讨论】:
-
我认为是错误。
-
我在GH的issues部分提交,你可以从这里追踪
issue #39903。
标签: python pandas dataframe sum