I am having some issues working with some data in a Pandas df. In my dataframe I have 3 columns...X,Y, and Z. I am trying to determine the amount of instances where Y > 0, after a row where X > 0, but Z in the subsequent rows remains less than a certain value. My psuedo code is below:
import datetime
import time
import pandas as pd
# Set number of rows to skip
rows_to_skip = 0
# Rows to use after skipped rows
rows_to_use = 10000
# Read the file (Adjust arguments accordingly)
data = pd.read_csv('example.csv',skiprows=rows_to_skip, error_bad_lines=False, nrows=rows_to_use, low_memory=False)
# Add headers when skipping rows
data.columns = ["X","Y","Z"]
# Psuedo Code Below
for variable in data['X']:
if variable > 0:
# Count number of times the following conditions are met in all subsequent rows:
condition 1 ) Y > 0
condition 2 ) Z <= (Z of the row where variable was > 0) + 0.5
# Then I want to take the count of these instances and append to a new column, but in the same row where X was originally greater than zero
Any suggestions from Pandas Pros out there would be awesome...I'll try to follow up with a notebook as well