+ 5
Pandas Problem
I need to create a column that contains a counter based on conditions in another column. For example, I have a column "Elapsed" which contains timestamps or the string "On Time". I need a column "On Time Count" that increments by 1 each time "On Time" is found in "Elapsed". I have looked through the book "Pandas in Action" but I don't see an example of such a process.
3 Answers
+ 3
Something like this might work, depending on your index:
counter = 0
for i in range(len(df)):
if df.loc[i, "Elapsed"] == "On Time":
counter += 1
df.loc[i, "On Time Count"] = counter
+ 6
Goathland1111 ,
can you please make a sample how the dataframe looks now, and what you expect to get with the new column. thanks.
+ 2
Tibor Santa Thank you very much.