Python Forum
How to update only two colums in database from csv without touching data in other col
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to update only two colums in database from csv without touching data in other col
#1
hi I have a database which looks like this image    

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:    
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Question on pandas.dataframe merging two colums shomikc 4 783 Jun-29-2023, 11:30 AM
Last Post: snippsat
  How to detect abnormal data in big database python vanphuht91 5 1,064 Jun-27-2023, 11:22 PM
Last Post: Skaperen
  Database that can compress a column, or all data, automatically? Calab 3 1,120 May-22-2023, 03:25 AM
Last Post: Calab
  Basic SQL query using Py: Inserting or querying sqlite3 database not returning data marlonbown 3 1,306 Nov-08-2022, 07:16 PM
Last Post: marlonbown
  simple html page with update data korenron 3 2,587 Nov-15-2021, 09:31 AM
Last Post: jamesaarr
  Get last row of SQL database and update Turtle 5 3,046 Oct-14-2021, 07:06 PM
Last Post: Turtle
  I need help parsing through data and creating a database using beautiful soup username369 1 1,688 Sep-22-2021, 08:45 PM
Last Post: Larz60+
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 2,116 Jul-02-2021, 02:19 PM
Last Post: xtc14
Photo Creating column in python based on the other colums value count Bartek635 2 2,893 Apr-15-2021, 03:47 PM
Last Post: Bartek635
  Scaler fit with different colums HoldYourBreath 0 1,296 Jan-10-2021, 11:53 AM
Last Post: HoldYourBreath

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020