How to spilt one field data and save it in 2 column in mysql?

316
August 14, 2017, at 4:58 PM

I have a csv file where field is terminated by comma, but in from one field I want to split it and save it in 2 columns. CSV looks like this:

UnifiedSearch_Pass,UnifiedSearch_Fail,Settings_Pass,Settings_Fail,Map_Overview_Pass,Map_Overview_Fail,Map_Guidance_Pass,Map_Guidance_Fail,RouteBar_Pass,RouteBar_Fail,MainMenu_Pass,MainMenu_Fail,SpeedCameras_Pass,SpeedCameras_Fail,MapManagement_Pass,MapManagement_Fail,AccountManagement_Pass,AccountManagement_Fail,VoiceManagement_Pass,VoiceManagement_Fail,Total_Automated_Tests,Total_Pass,Total_Fail
177,8,57,5,90,6,48,3,48,6,109,12,17,2,14,0,12,0,10,0,624,582,42

Printing the row[0] gives UnifiedSearch_Pass \n 177

import csv
import MySQLdb 
connection = MySQLdb.Connect(host='localhost', user='root', passwd='root', db='mydb')
cursor = connection.cursor()
query = "LOAD DATA LOCAL INFILE '/Users/izmir_new/Documents/Dashboard/CSV_FILE/testResults.csv' INTO TABLE EpicDetails FIELDS TERMINATED BY ','"
cursor.execute( query )
connection.commit()

Output

+--------------------+--------+
| EpicName           | Result |
+--------------------+--------+
| UnifiedSearch_Pass |      0 |
| 177                |      8 |
+--------------------+--------+

What I want is the output should be:

+--------------------+--------+
| EpicName           | Result |
+--------------------+--------+
| UnifiedSearch_Pass |     177|             
+--------------------+--------+

Any help will be much appreciated! Thanks!

Rent Charter Buses Company
READ ALSO
How to append list to second list (concatenate lists)

How to append list to second list (concatenate lists)

How do I concatenate two lists in Python?

485
how to send email with Excel file (xlsx)attachment in Python

how to send email with Excel file (xlsx)attachment in Python

I need to send a email with Excel attachment。 my code is like below , it is ok to send the email , but when I received the email, the attachment file is not Excel files~~ it seems that the wrong format I have attached~~~

951
Jelastic Apache+mod_wsgi: 'module' object is not callable

Jelastic Apache+mod_wsgi: 'module' object is not callable

I have unsuccessfully tried to install my Flask application to a Jelastic serverI have there Apache 2

343
Django Save and add another behaviour modification

Django Save and add another behaviour modification

In my django admin console i would that after user press "Save and add another" button the fields value of the form remain populate with last values inserted but i don't know if and how this could be possibleSomeone could help me?

356