vendredi 19 novembre 2021

Append row to empty dataframe with no schema based on conditional gives error not defined

db = pd.read_csv('/Users/janaina/Documents/App/Data/cosmetics.csv')
nsdb = pd.read_excel('/Users/janaina/Documents/App/Data/Non Sensitising 
Products.xlsx')

def addnsproduct(nsp):
    if nsp in db.Name.values :
        print("Recognised product")
        nsdb = nsdb.append(db.loc[db['Name'] == nsp])
    else : 
        print("Not in database")

nsp = input("Enter product that does not sensitise your skin: ")

addnsproduct(nsp)
print(nsdb)

I get an error saying that nsdb (the one after the =) is not defined.

Please note that nsdb is a blank file, no columns.

Thanks!

Aucun commentaire:

Enregistrer un commentaire