Question: suppose I have a data frame:

```
df<-data.frame(specie=c('apple','banana','orange'),total=c(1000,500,850),fresh=c(NA,250,700),processed=c(NA,250,150))

```

Note that for Apple, only Total value is available.
I would like to create a bar plot that show both fresh and processed values for each specie, and show only total value for the case of Apple where fresh and processed values are NAs.

I tried with the codes below, but didn't get the plot I want:

```
p<-df %>% ggplot(aes(x=total,y=specie))
p+geom_col()+geom_col(aes(x=fresh,fill="fresh"))+geom_col(aes(x=processed,fill="processed"))

```

Why total area exceeds fresh and processed?

![](https://i.stack.imgur.com/lwXmm.png)

Answer: 
Have your function accept the columns names and values as keyword arguments, and pass them directly to the `values` method or the model's initialiser.

```py
def db_update(a_p, **values):
   q = session.query(Log).filter(Log.access_point == a_p)
   if session.query(q.exists()).scalar():
        stmt = update(Log).where(Log.access_point == a_p).values(**values)
        session.execute(stmt)
   else:
        new_point = Log(access_point = a_p, **values)
        session.add(new_point)

db_update(1, admin='Alice')

```

If your table should gain additional columns you will be able to update them without changing the function code.
You could use a dictionary.

Here's an example with some mock functions:

```py
def update_admin():
    return 1
def update_staff():
    return 2
def update_consult():
    return 3
def update_visitor():
    return 4

update_dict = {
    'admin': update_admin,
    'staff': update_staff,
    'consult': update_consult,
    'visitor': update_visitor}

print(update_dict['staff']())
# 2

print(update_dict['visitor']())
# 4

```