Feb-03-2021, 10:53 AM
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
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.
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.