Python Forum
How to update only two colums in database from csv without touching data in other col - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to update only two colums in database from csv without touching data in other col (/thread-12347.html)



How to update only two colums in database from csv without touching data in other col - Prince_Bhatia - Aug-21-2018

hi I have a database which looks like this image [attachment=456]

i have a csv which has two columns City and Main_city. I want to update Main_City against the City column from csv into database but without damaging other data into the database. How can i do this?

I do not know the logic behind it.

below are my codes:
import csv

data_obj = {}
def readfiles():
    f = open("city.csv", "r")
    data = f.read()
    lst = data.split("\n")
    for i in range(1, len(lst)):
        val = lst[i].split(",")
        data_obj[val[0]] = val[1]
        #print(data_obj[val[0]])
    print(data_obj)
readfiles()

conn = sqlite3.connect('99_data_increment.db')
c = conn.cursor()
c.execute("CREATE TABLE IF NOT EXISTS crawled (id INTEGER PRIMARY KEY, State , XID , Project_Name , City , Main_City , Registration_Number , Promoter_Name , Rera_URL , PDF_text, Crawled_Date , Status, Names, Transaction_Date, Comments, Call_Contact_Number, Creation_Type, Builder_Website)")
New_project_db.insert(statess, XID, Projectname, City, maincity, Registration_number, promotername, rera_url, blank, fdate, "CREATED", agents_names, fdate, blank, blank, blank, blank)
## didn't getting logic behind
My csv looks like this:[attachment=457]