How to assign a value to a column for every row of pandas dataframe?
You're looking for a cartesian product of both dataframes. One way around this in pandas is to create a common and unique key for both dataframes and perform a merge
(any, as there is a complete overlap):
df.assign(key=0).merge(object_raw.assign(key=0), on='key').drop(['key'], axis=1)
brand_name category_id object_name
0 Nike 24 T-shirt
1 Nike 45 Shorts
2 Nike 32 Dress
3 Lacoste 24 T-shirt
4 Lacoste 45 Shorts
5 Lacoste 32 Dress
6 Adidas 24 T-shirt
7 Adidas 45 Shorts
8 Adidas 32 Dress
Another way using itertools.product()
which gives Cartesian product of input iterables.
import itertools
df=(pd.DataFrame(list(itertools.product(brand_name.brand_name,object_raw.object_name))
,columns=['brand_name','object_name']))
df['category_id']=df['object_name'].map(object_raw.set_index('object_name')['category_id'])
print(df)
brand_name object_name category_id
0 Nike T-shirt 24
1 Nike Shorts 45
2 Nike Dress 32
3 Lacoste T-shirt 24
4 Lacoste Shorts 45
5 Lacoste Dress 32
6 Adidas T-shirt 24
7 Adidas Shorts 45
8 Adidas Dress 32