0

Referring to Set value for particular cell in pandas DataFrame I see

 df.set_value( rownum, colnum, 'Someval') 

to set a given cell. Assume in my dataframe all the columns are integers.

Is there a way to use

set_value 

to set a range of columns in a given row, or do I need a different function?

df.set_value ( rownum, colstart:colend, 'someval') 

gave a syntax error.

After some contortion I found this:

df.ix[ rownum , colstart:colend] = 'Someval' 

This one works but I was wondering about set_value or perhaps some other short way.

Community
  • 1
  • 1
Mark Ginsburg
  • 1,589
  • 2
  • 14
  • 23

1 Answers1

1

As noted directly above by @MaxU, you are looking for

df.iloc[ rownum , colstart:colend] = 'Someval'
pml
  • 410
  • 3
  • 12
  • This works; note: I noticed comparing the two that df.ix [ row, colstart:colend ] = 'someval' includes colend while df.iloc [ row, colstart:colend ] = 'someval' does not include colend. – Mark Ginsburg Mar 10 '17 at 00:49
  • Yep - .iloc is specifically for integer column values. Also, note that the pandas docs generally favor using .loc as a successor to .ix – pml Mar 10 '17 at 09:02