I’ve got a column within a df labelled a. It contains a list of string values. I want to return if they are consecutive or not.
I can do it passing in a single list but I want to iterate over each row.
df = pd.DataFrame({'a':[[10,11,12], [10,11,12], [10,11,12], [10,11,13]],
})
def cons(L):
return all(n-i==L[0] for i,n in enumerate(L))
print(cons(df['a'][0])) # works
df['cons'] = df['a'].apply(cons, axis = 1) # error
intended:
a cons
0 [10, 11, 12] True
1 [10, 11, 12] True
2 [10, 11, 12] True
3 [10, 11, 13] False