Skip to content

Instantly share code, notes, and snippets.

def sub_brand_finder(subcategory):
temp=cscp[cscp['PrimaryCategory']=='Makeup Products (non-permanent)']
df=temp[temp['SubCategory']==subcategory].groupby('brandname').agg({'ChemicalCount':np.mean,'BrandName':'first'}).sort_values('ChemicalCount').reset_index()
least=str(np.array(df.head(3)['BrandName']))[1:-1]
most=str(np.array(df.tail(3)['BrandName']))[1:-1]
text1 = "\033[32m"
text2 = "\033[31m"
print("\033[1m",text1,'The three most chemical-safe brands in '+subcategory+' are '+least)
print("\033[1m",text2,'The three least chemical-safe brands in '+subcategory+' are '+most)
for i in makeup_subcategories:
def brand_finder(category):
df=cscp[cscp['PrimaryCategory']==category].groupby('BrandName').agg(np.mean).sort_values('ChemicalCount').reset_index()
least=str(np.array(df.head(3)['BrandName']))[1:-1]
most=str(np.array(df.tail(3)['BrandName']))[1:-1]
text1 = "\033[32m"
text2 = "\033[31m"
print("\033[1m",text1,'The three most chemical-safe brands in '+category+' are '+least)
print("\033[1m",text2,'The three least chemical-safe brands in '+category+' are '+most)
cscp.groupby('ChemicalName').size().to_frame().rename({0:'count'},axis=1).sort_values('count',ascending=False).head(5)
most_chemical_brands=chemical_count.sort_values('ChemicalCount',ascending=False).query('ChemicalCount>2')
most_chemical_brands.head(5)
@geetashankar
geetashankar / cscp1.py
Created January 5, 2021 07:53
cleaning chemical cosmetic data
cscp['BrandName']=cscp['BrandName'].str.lower().str.replace('.','').str.replace(' ','').str.replace('�','')
cscp['ProductName']=cscp['ProductName'].str.lower()
cscp['ChemicalName']=cscp['ChemicalName'].str.lower()
@geetashankar
geetashankar / chemicals_in_cosmetics.ipynb
Created January 5, 2021 07:42
Introductory exploration of chemicals in cosmetics using Pandas
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.