I am trying to create new column in pandas dataframe with row number as condition using iloc.
This is my code:
import pandas as pd
shop=pd.DataFrame.from_dict(data)
def cate_shop (shop):
if shop==shop.iloc[:4]:
return 'Service'
if shop==shop.iloc[4:140]:
return 'Food & Beverage'
if shop==shop.iloc[140:173]:
return 'Fashion'
if shop==shop.iloc[173:197]:
return 'Electronics'
return 'Other'
shop['category']=shop.apply(lambda shop: cate_shop(shop), axis=1)
Appreciate any guidance as i have no idea what went wrong.