Mark Ginsburg
Mark Ginsburg

Reputation: 2269

Set values for particular columns in a row of a Pandas Dataframe

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.

Upvotes: 0

Views: 2852

Answers (1)

pml
pml

Reputation: 504

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

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

Upvotes: 1

Related Questions