I am new to learning numpy. I write the statement as follows to count the number of Buy and Sell, but doesnt work.
count = np.where(((df.Buy == 1) & (df.Sell== 0)), count 1, count)
and return error message:
ValueError: operands could not be broadcast together with shapes (9,) (0,) (0,)
Any suggestion. Thanks
CodePudding user response:
It looks like you're attempting to count how many times Buy == 1 and Sell == 0 at the same time. One way to do this is:
count = ((df.Buy == 1) & (df.Sell== 0)).sum()
CodePudding user response:
Or you can use this as well:
count = df.query('(Buy == 1) and (Sell == 0)').shape[0]