I've got a column within a df labelled a. It contains a list of int 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': [[0,2], [9,11,12], [0,1,2], [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 [0, 2] False
1 [9, 11, 12] False
2 [0, 1, 2] True
3 [10, 11, 13] False
TypeError: cons() got an unexpected keyword argument 'axis', becauseaxisisn't a valid keyword argument forSeries.apply(), since there's only one axis. In the future, please make a minimal reproducible example including the error, and ask a specific question about it. Stack Overflow is a Q&A site after all. Check out the tour if you haven't already. for more tips, see How to Ask.