Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If Then statement
#4
I would guess that df3 is a dataframe with column 'diff' with int or float dtype. In that case, as nilamo pointed out with 3), its similar to iterating over list of numbers and your "changes" do not propagate into your dataframe column.

Iterating over serie/dataframe is only rarely needed, using subsetting(indexing) or .apply() is preferred (if possible). You can use subsetting with condition and assign new value directly:
df3['diff'][df3['diff'] < 0] = NaN   # I suppose that you did "from numpy import *"
Reply


Messages In This Thread
If Then statement - by smw10c - Apr-24-2017, 03:15 PM
RE: If Then statement - by wavic - Apr-24-2017, 03:45 PM
RE: If Then statement - by nilamo - Apr-24-2017, 03:55 PM
RE: If Then statement - by zivoni - Apr-24-2017, 04:15 PM
RE: If Then statement - by nilamo - Apr-24-2017, 04:18 PM
RE: If Then statement - by zivoni - Apr-24-2017, 04:27 PM
RE: If Then statement - by smw10c - Apr-24-2017, 04:30 PM
RE: If Then statement - by nilamo - Apr-24-2017, 04:39 PM
RE: If Then statement - by smw10c - Apr-24-2017, 04:41 PM
RE: If Then statement - by zivoni - Apr-24-2017, 05:08 PM
RE: If Then statement - by smw10c - Apr-24-2017, 05:17 PM
RE: If Then statement - by snippsat - Apr-24-2017, 04:19 PM
RE: If Then statement - by smw10c - Apr-24-2017, 04:25 PM
RE: If Then statement - by zivoni - Apr-24-2017, 04:47 PM
RE: If Then statement - by smw10c - Apr-24-2017, 04:55 PM
RE: If Then statement - by zivoni - Apr-24-2017, 05:35 PM
RE: If Then statement - by smw10c - Apr-24-2017, 07:16 PM
RE: If Then statement - by zivoni - Apr-24-2017, 07:59 PM
RE: If Then statement - by smw10c - Apr-24-2017, 08:10 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020