Friday 15 August 2014

python - How to subtract 1 from each value in a column in Pandas -


I think this should be a simple problem, but I can not find a solution

Within a subset of rows in a dataframe, I need to decrease the value of each item in column 1. I have tried many approaches, but the values ​​remain unchanged. After another entry on SO, I tried

  def minus1 (x): x = x-1 returns x plage [pledges.Source == 'M0607']. DayOFDrive = Pledge [pledges.Source == 'M0607']. DayOFDrive.map (minus1)   

when I wrote

  pledge [pledges.Source == 'M0607']. DayOFDrive   

To check this, the original unchanged data came back. I have also tried pledges.Source == 'M0607']. DayOFDrive = Pledge [pledges.Source == 'M0607']. DayOFDrive-1

What does nothing

How can I reduce all values ​​of 1 in a column for a subset of rows?

If it returns the data that you want to modify:

 < Code> pledges [pledges.Source == 'M0607']. DayOFDrive   

Try again to modify it:

  Pledge [pledges.Source == 'M0607']. DayOFDrive - = 1    

No comments:

Post a Comment