Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
creating a loop
#1
Hello,

I have a line of code that works fine for a single column in the data frame. I would now like to convert this so that it finds all the columns in the data frame (returnsall)and passes them through this line.

The line of code is
stock= 'T.TO'
seriesObj = returnsall.apply(lambda x: True if x[stock] > 2 else False , axis=1)
# Count number of True in series
numOfRows = len(seriesObj[seriesObj == True].index)
print('Number of Rows in dataframe in which change > 5 : ', numOfRows)
The returnsall dataframe looks like this:

BCE.TO RCI-B.TO T.TO
Date
2010-01-05 -1.476648 -1.827309 -0.087740
2010-01-06 -0.522831 -0.192583 0.087817
2010-01-07 -2.592855 -0.482278 -0.380206
2010-01-08 0.143890 1.357011 0.763314
2010-01-11 -0.395117 1.880815 -0.641015

Any help would be appreciated. thanks.
Reply
#2
Any thoughts anyone
Reply
#3
Could you share a larger example that we can run and play around with?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,483 Jul-27-2022, 08:50 PM
Last Post: rob101
  Creating a variables inside FOR loop zazas321 5 4,101 Sep-16-2020, 04:42 PM
Last Post: Naheed
  Need help creating complex loop around existing script CephloRhod 5 2,770 Apr-16-2020, 01:23 PM
Last Post: deanhystad
  Need help creating a loop codingnewbie 1 1,616 Jul-18-2019, 11:12 PM
Last Post: Yoriz
  Com Error with macro within for loop due to creating new workbook in the loop Lastwizzle 0 1,361 May-18-2019, 09:29 PM
Last Post: Lastwizzle
  Question about for loop not creating an infinite loop. FWendeburg 1 2,117 Feb-03-2019, 08:45 PM
Last Post: ichabod801
  I need help with loop one function and creating variables don 3 2,808 Jan-24-2019, 07:31 AM
Last Post: buran
  Creating a variable in for loop dan789 9 4,160 Dec-19-2018, 06:23 PM
Last Post: nilamo
  Creating multiple lists from file without long for loop Curtnos 2 4,449 Jan-28-2018, 09:11 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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