Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 900729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:26:15+00:00 2026-05-15T15:26:15+00:00

I have a Python script which uses the MySQLdb interface to load various CSV

  • 0

I have a Python script which uses the MySQLdb interface to load various CSV files into MySQL tables.

In my code, I use Python’s standard CSV library to read the CSV, then I insert each field into the table one at a time, using an INSERT query. I do this rather than using LOAD DATA so that I can convert null values and other minor clean-ups on a per-field basis.

Example table format:

`id_number` | `iteration` | `date`     | `value`
102         | 1           | 2010-01-01 | 63
102         | 2           | 2010-01-02 | NULL
102         | 3           | 2010-01-03 | 65

The null value in the second iteration of id_number = 102 represents a case where value hasn’t changed from the previous day i.e. value remains 63.

Basically, I need to convert these null values to their correct values. I can imagine 4 ways of doing this:

  1. Once everything is inserted into the table, run a MySQL query that does the iterating and replacing all by itself.

  2. Once everything is inserted into the table, run a MySQL query to send some data back to Python, process in Python then run a MySQL query to update the correct values.

  3. Do the processing in Python on a per-field basis before each insert.

  4. Insert into a temporary table and use SQL to insert into the main table.

I could probably work out how to do #2, and maybe #3, but have no idea how to do #1 or #4, which I think are the best methods as it then requires no fundamental changes to the Python code.

My question is A) which of the above methods is “best” and “cleanest”? (Speed not really an issue.) and B) how would I achieve #1 or #4?

Thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:26:16+00:00Added an answer on May 15, 2026 at 3:26 pm

    I think you would have the most control and the least amount of work with your #3 option, Especially if you want to keep existing values over null values, I think you risk overwriting those with #1.

    If speed is not an issue, for every record in your CSV, compare it to the existing record, and update or insert your record with your preferred values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 513k
  • Answers 513k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you're planning to use has_and_belongs_to_many, you should probably switch… May 16, 2026 at 5:59 pm
  • Editorial Team
    Editorial Team added an answer Eclipse PDT is great for those who are familiar with… May 16, 2026 at 5:59 pm
  • Editorial Team
    Editorial Team added an answer I created a demo including a real-time heatmap with the… May 16, 2026 at 5:59 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

In my Python script which uses Curses, I have a subwin to which some
I have a Python script which uses Tkinter for the GUI. My little script
I have a python script which uses subprocess.Popen to run multiple instances of another
I have python script that uses pysvn and checks out or updates a local
I'm trying to compile my python script into a single .exe using gui2exe (which
I have a python script which scrapes a page and receives a cookie. I
I'm trying to solve the following problem: Say I have a Python script (let's
In a python script, I started a bunch of threads, each of which pulls
Is there a Python script or tool available which can remove comments and docstrings
Most web applications have a Location field, in which uses may enter a Location

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.