So I've connected my Postgresql database into Python with Psycopg2, and I've pulled two specific columns to update. The first column I have used as the keys in a Python dictionary, and I have run some functions on the second one and use the results as the values in the dictionary. Now what I want to do is add those values back into Postgresql table as a new column, but I want them to pair with the correct keys they are paired with in the dictionary. Essentially, I want to take dictionary values and insert them as a new column and pick which "key" in the Postgresql table they belong to (however, I don't want to manually assign them, because, well, there's hopefully a better way).
Postgresql Table
|col1 |col2 |col3 | ... | coln
row1 | a1 | b1 | c1 | ... | n1
row2 | a2 | b2 | c2 | ... | n2
... | ... | ... | ... | ... | n...
rowm | am | bm | cm | ... | nm
This is the dictionary I made in Python, where f() is a series of functions ran on variable:
{
a1 : f(c1),
a2 : f(c2),
... : ...
}
Now my goal is to add the values column back into my table so that it corresponds to the original keys. Ideally, to look something like this:
|col1|col2|col3| ... |newcol| coln
row1 | a1 | b1 | c1 | ... | f(c1)| n1
row2 | a2 | b2 | c2 | ... | f(c2)| n2
... | ...| ...| ...| ... | ... | n...
rowm | am | bm | cm | ... | f(cm)| nm
I know I can insert the column into the table, but not sure how to pair it with keys. Any help is very much appreciated!
col1the primary key for the db table? (it is the key in the python dict)