python - Change row values based on a range of indices in pandas? -




i have dataset this:

index   _id first   last    date 0       11  john    doe     2016-01-01 1       12  jane    doe     2016-01-06 2       13  jack    hammer  2016-01-06 3       14  peter   dex     2016-01-10 

i want change date 2016-01-06 2016-01-10 based on range of index(1-2 in case). how can that?

thanks!

is there involved logic or methodology behind this? if not, can access slice using df.loc:

in [354]: df.loc[df.index.isin([1, 2]), 'date'] = '2016-01-10'  in [355]: df out[355]:     index  _id  first    last        date 0      0   11   john     doe  2016-01-01 1      1   12   jane     doe  2016-01-10 2      2   13   jack  hammer  2016-01-10 3      3   14  peter     dex  2016-01-10 

you can substitute [1, 2] range object:

df.loc[df.index.isin(range(1, 3)), 'date'] = '2016-01-10' 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -