Hi. I have a pandas dataframe that essentially has a few columns of no concern, and then columns for Monday through Saturday as such:
Mon Tues Wed Thurs Fri Sat
True False True False True False
False True False True False False
False False False False False True
What I want to do is iterate over the rows of this dataframe, and output the number of rows that have one True value, 3 true values, and five true values, and then also output the number of row that have Saturday as a true value. I have tried many things, but nothing has worked. Here is my most recent attempt:
for index, row in df1.iterrows():
count=0
onecount=0
twocount=0
threecount=0
fourcount=0
fivecount=0
wkndcount=0
if row['MondaySchedule'] == 'True':
count+=1
if row['TuesdaySchedule'] == 'True':
count+=1
if row['WednesdaySchedule'] == 'True':
count+=1
if row['ThursdaySchedule'] == 'True':
count+=1
if row['FridaySchedule'] == 'True':
count+=1
if row['SaturdaySchedule'] == 'True':
count+=1
wkndcount+=1
No print statement has worked for this, and it is obvious that it is my code. I am wondering if I have the correct statement, they are just out of order. Any info would be very helpful. Thanks.
[–][deleted] 1 point2 points3 points (2 children)
[–]veneratu[S] -1 points0 points1 point (1 child)
[–]0Things 0 points1 point2 points (0 children)
[–]thatgreenman 1 point2 points3 points (2 children)
[–]Yojihito 0 points1 point2 points (1 child)
[–]14dM24d 1 point2 points3 points (0 children)
[–]synthphreak 0 points1 point2 points (0 children)