[英]Why it says NaN when I'm trying to sum rows using Python Pandas?
Title Netquantity Bases Chambers
x 2 4
y 5
To get the total of bases chambers, I've used为了得到基地室的总数,我用过
concat_list.loc['Total'] = concat_list[['Bases','Chambers']].sum()
However, the output was然而,output 是
Title Netquantity Bases Chambers
x 2 4
y 5
Total NaN NaN NaN
Could you help me to debug this issue?你能帮我调试一下这个问题吗? Some of the numbers are empty.
有些号码是空的。 I tried to
我尝试过了
concat_list = concat_list.fillna(0)
But still didn't work.但仍然没有工作。
Here is problem there are values mixed strings with numeric or all strings, first tray convert to floats
:这里的问题是值混合字符串与数字或所有字符串,第一个托盘转换为
floats
:
concat_list.loc['Total'] = concat_list[['Bases','Chambers']].astype(float).sum()
If not working, try replace not parseable values to missing values by to_numeric
per all columns, so use DataFrame.apply
:如果不起作用,请尝试将不可解析的值替换为所有列的
to_numeric
缺失值,因此请使用DataFrame.apply
:
concat_list.loc['Total'] = concat_list[['Bases','Chambers']].apply(pd.to_numeric, errors='coerce').sum()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.