I have a DataFrame with 3 columns and 1,000+ rows,
df
day product order
2010-01-01 150ml Mask 9
2010-01-02 230ml Lotion 27
2010-01-03 600ml Shampoo 33
And I would like to subset each product as following,
df_mask df_lotion df_shampoo
day order day order day order
2010-01-01 9 2010-01-02 27 2010-01-03 33
2010-01-09 8 2010-01-05 30 2010-01-04 25
2010-01-11 13 2010-01-06 29 2010-01-06 46
This is how I do it,
# Create a product list
productName = df['product'].tolist()
# Subsetting
def subtable(df,productName):
return (df[(df['product'] == productName)])
# Subsetting
df_mask = subtable(df, '150ml Mask')
df_lotion = subtable(df, '230ml Lotion')
df_shampoo = subtable(df, '230ml Shampoo')
Is there any way I can get all the subsets one time using for loop since the data frame has many different products.