0

I am running below code and getting an error. I can run:

r.at[0,'_foreign_notional_sum'] = s

What am I doing wrong?

Error producing code:

s=0
r['_foreign_notional_sum'] = 0.0
for index,row in r.iterrows():
  s=s+r._foreign_notional
  index
  r.at[index,'_foreign_notional_sum'] = s  

-- error:

File "pandas/_libs/src\util.pxd", line 150, in util.set_value_at File "pandas_libs\index.pyx", line 142, in pandas._libs.index.IndexEngine.get_loc ValueError: setting an array element with a sequence.

gene golub
  • 51
  • 3
  • 7
  • Hi. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael Sep 04 '18 at 06:13

1 Answers1

0

That error means s is a sequence. I suppose your r._foreign_notional is a Series, and your s + r._foreign_notional is a giving you a Series (hence s = s + r._foreign_notional is a Series).

You are probably looking for s += row['_foreign_notional'].

Please update your code though, as the current syntax is not valid.

If you are looking to update an entire column, you can simply use r['_foreign_notional_sum'] += s.

iamanigeeit
  • 784
  • 1
  • 6
  • 11