I want to do this in a pythonic way without using 1) a nested if statement and 2) the use of iterrows.
I have columns
Date in | Date Out | 1/22 | 2/22 | ... | 12/22
1/1/19 5/5/22
5/5/22 7/7/22
for columns like '1/22', I want to insert a calculated value which would be one of the following:
- Not Created Yet
- Closed
- Open
For the first row, column 1/22 would read "Open" because it was opened in Jan/22. This would continue until column 5/22, in which it would be labeled "Closed."
For the second row, column 1/22 would read "Not Created Yet" until 5/22 which would read "Open" until 7/22 which would have the value "Closed."
I don't need the full table necessarily, but I want to get a count of how many are closed/open/not created yet for every month.
Here is the code I'm using which works, but just takes longer than I think it could:
table={}
for i in mcLogsClose.iterrows():
table[i[0]] = {}
for month in pd.date_range(start='9/2021', end='9/2022', freq='M'):
if i[1]['Notif Date'] <= month:
if i[1]['Completion Date'] <= month:
table[i[0]][month]="Closed"
else:
table[i[0]][month]="Open"
else:
table[i[0]][month]="Not Yet Created"
I then want to run table['1/22'].value_counts()
Thanks for your attention!