I have a pandas dataframe that goes like below,
df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar','foo', 'bar', 'foo', 'foo'],
'seconds' : [21,200,300,400,500,600,700,800]})
I am trying to create buckets based on minutes as below,
def create_bucket(seconds):
#row['seconds'], buckets- 5,10,15,20,25,30,>30
if [(seconds >= 0) & (seconds <= 300)]:
result = "5"
elif [(seconds >= 301) & (seconds <= 600)]:
result = "10"
elif [(seconds >= 601) & (seconds <= 900)]:
result = "15"
elif [(seconds >= 901) & (seconds <= 1200)]:
result = "20"
elif [(seconds >= 1201) & (seconds <= 1500)]:
result = "25"
elif [(seconds >= 1501) & (seconds <= 1800)]:
result = "30"
else:
result = ">30"
return result
df['Bucket'] = df.apply(lambda row: create_bucket(df['seconds']), axis=1)
The result i get is 5 for all values. I'm trying to figure out what is wrong with the function create_bucket. Any help will be appreciated.
A seconds Bucket
0 foo 21 5
1 bar 200 5
2 foo 300 5
3 bar 400 5
4 foo 500 5
5 bar 600 5
6 foo 700 5
7 foo 800 5