Skip first row and delete certain char before importing csv to db












0















I'm new to Python, and my task is to import the csv to mysql database. I have this sample values inside my csv file:



SHA1,VSDT,TRX
005c41fc0f8580f51644493fcbaa0d2d468312c3,(WIN32 (EXE 7-2)),Ransom.Win32.TRX.XXPE50FFF027,
006ea7ce2768fa208ec7dfbf948bffda9da09e4e,WIN32 EXE 2-2,TROJ.Win32.TRX.XXPE50FFF027,


My problem here is, how can I remove "( " and ")" only at the start and end point of string at the second column before importing to database?



I have this code to import the csv



import csv
import mysql.connector
file = open(fullPath, 'rb')
csv_data = csv.reader(file)

mycursor = mydb.cursor()
cursor = mydb.cursor()
for row in csv_data:
cursor.execute('INSERT INTO jeremy_table_test(sha1,vsdt,trendx)'
'VALUES(%s, %s, %s)',[(row[0]),(row[1]),(row[2]))
mydb.commit()
cursor.close()
print("Done")









share|improve this question

























  • You get the IO error because you transact on f1 after you closed it, i.e., it's outside the indentation of the with open() as f1 section.

    – directive-41
    Nov 15 '18 at 5:51
















0















I'm new to Python, and my task is to import the csv to mysql database. I have this sample values inside my csv file:



SHA1,VSDT,TRX
005c41fc0f8580f51644493fcbaa0d2d468312c3,(WIN32 (EXE 7-2)),Ransom.Win32.TRX.XXPE50FFF027,
006ea7ce2768fa208ec7dfbf948bffda9da09e4e,WIN32 EXE 2-2,TROJ.Win32.TRX.XXPE50FFF027,


My problem here is, how can I remove "( " and ")" only at the start and end point of string at the second column before importing to database?



I have this code to import the csv



import csv
import mysql.connector
file = open(fullPath, 'rb')
csv_data = csv.reader(file)

mycursor = mydb.cursor()
cursor = mydb.cursor()
for row in csv_data:
cursor.execute('INSERT INTO jeremy_table_test(sha1,vsdt,trendx)'
'VALUES(%s, %s, %s)',[(row[0]),(row[1]),(row[2]))
mydb.commit()
cursor.close()
print("Done")









share|improve this question

























  • You get the IO error because you transact on f1 after you closed it, i.e., it's outside the indentation of the with open() as f1 section.

    – directive-41
    Nov 15 '18 at 5:51














0












0








0








I'm new to Python, and my task is to import the csv to mysql database. I have this sample values inside my csv file:



SHA1,VSDT,TRX
005c41fc0f8580f51644493fcbaa0d2d468312c3,(WIN32 (EXE 7-2)),Ransom.Win32.TRX.XXPE50FFF027,
006ea7ce2768fa208ec7dfbf948bffda9da09e4e,WIN32 EXE 2-2,TROJ.Win32.TRX.XXPE50FFF027,


My problem here is, how can I remove "( " and ")" only at the start and end point of string at the second column before importing to database?



I have this code to import the csv



import csv
import mysql.connector
file = open(fullPath, 'rb')
csv_data = csv.reader(file)

mycursor = mydb.cursor()
cursor = mydb.cursor()
for row in csv_data:
cursor.execute('INSERT INTO jeremy_table_test(sha1,vsdt,trendx)'
'VALUES(%s, %s, %s)',[(row[0]),(row[1]),(row[2]))
mydb.commit()
cursor.close()
print("Done")









share|improve this question
















I'm new to Python, and my task is to import the csv to mysql database. I have this sample values inside my csv file:



SHA1,VSDT,TRX
005c41fc0f8580f51644493fcbaa0d2d468312c3,(WIN32 (EXE 7-2)),Ransom.Win32.TRX.XXPE50FFF027,
006ea7ce2768fa208ec7dfbf948bffda9da09e4e,WIN32 EXE 2-2,TROJ.Win32.TRX.XXPE50FFF027,


My problem here is, how can I remove "( " and ")" only at the start and end point of string at the second column before importing to database?



I have this code to import the csv



import csv
import mysql.connector
file = open(fullPath, 'rb')
csv_data = csv.reader(file)

mycursor = mydb.cursor()
cursor = mydb.cursor()
for row in csv_data:
cursor.execute('INSERT INTO jeremy_table_test(sha1,vsdt,trendx)'
'VALUES(%s, %s, %s)',[(row[0]),(row[1]),(row[2]))
mydb.commit()
cursor.close()
print("Done")






python mysql csv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 6:56







Godshand

















asked Nov 15 '18 at 5:40









GodshandGodshand

989




989













  • You get the IO error because you transact on f1 after you closed it, i.e., it's outside the indentation of the with open() as f1 section.

    – directive-41
    Nov 15 '18 at 5:51



















  • You get the IO error because you transact on f1 after you closed it, i.e., it's outside the indentation of the with open() as f1 section.

    – directive-41
    Nov 15 '18 at 5:51

















You get the IO error because you transact on f1 after you closed it, i.e., it's outside the indentation of the with open() as f1 section.

– directive-41
Nov 15 '18 at 5:51





You get the IO error because you transact on f1 after you closed it, i.e., it's outside the indentation of the with open() as f1 section.

– directive-41
Nov 15 '18 at 5:51












2 Answers
2






active

oldest

votes


















1














MySQL LOAD DATA tool can probably do what you want here. Here is what the LOAD DATA call might look like:



LOAD DATA INFILE 'path/to/rb'
INTO TABLE jeremy_table_test
FIELDS TERMINATED BY ','
LINES TERMINATED BY 'rn' -- or 'n'
IGNORE 1 LINES
(sha1, @var1, trendx)
SET vsdt = TRIM(TRAILING ')' FROM TRIM(LEADING '(' FROM @var1));


To make this call from your Python code, you may try something like this:



query = "LOAD DATA INFILE 'path/to/rb' INTO TABLE jeremy_table_test FIELDS TERMINATED BY ',' LINES TERMINATED BY 'rn' IGNORE 1 LINES (sha1, @var1, trendx) SET vsdt = TRIM(TRAILING ')' FROM TRIM(LEADING '(' FROM @var1))"
cursor.execute(query)
connection.commit()





share|improve this answer


























  • can you edit it in full code? I can't understand the formatting of load data infile, just a newbie here

    – Godshand
    Nov 15 '18 at 5:56











  • I don't understand your request. My answer is about as clear as it can be. You might want to try running LOAD DATA first from the command line, to make sure that there are no issues there. Then, once you are sure it works, try running it from your Python code.

    – Tim Biegeleisen
    Nov 15 '18 at 5:58











  • tried it but gives me ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IGNORE 1 LINES' at line 1

    – Godshand
    Nov 15 '18 at 6:09











  • great but how can i use load data using variable, my variable is like this: fullPath = mypath + "\" + theFile using fullPath

    – Godshand
    Nov 15 '18 at 6:18











  • I don't understand your question.

    – Tim Biegeleisen
    Nov 15 '18 at 6:25



















2














Skip the row when you read it in, rather than when you write it.



with open(fullPath, 'rb') as file:
csv_data = csv.reader(file)
next(csv_data)
mycursor = mydb.cursor()
cursor = mydb.cursor()
for row in csv_data:
cursor.execute('INSERT INTO jeremy_table_test(sha1,vsdt,trendx)'
'VALUES(%s, %s, %s)',[(row[0]),(row[1]),(row[2]))
mydb.commit()
cursor.close()
print("Done")





share|improve this answer


























  • thanks, now my only problem is to delete the chars in my second column

    – Godshand
    Nov 15 '18 at 5:53






  • 1





    Can u explain why two different cursors are taken? Tough only 1 is used. And in next(csvreader) what is csvreader?

    – Shivam Seth
    Nov 15 '18 at 5:59











  • Yeah, to be honest I din't look at that part of the code, just cleaned up the bit OP asked about. There is no need for the lines referring to mydb.commit().

    – directive-41
    Nov 15 '18 at 6:36











  • @Godshand, just use string slicing to remove the unwanted characters if they are only the first and last, and are consistently present. E.g., row[1][1:] will drop the first character from your 2nd column value every time. If they are only present on some rows, then you will need something trickier, probably use regex.

    – directive-41
    Nov 15 '18 at 6:41













  • @ Shivam Seth, my bad typing is the reason for the error in next() - fixed now, thanks.

    – directive-41
    Nov 15 '18 at 6:47











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313098%2fskip-first-row-and-delete-certain-char-before-importing-csv-to-db%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














MySQL LOAD DATA tool can probably do what you want here. Here is what the LOAD DATA call might look like:



LOAD DATA INFILE 'path/to/rb'
INTO TABLE jeremy_table_test
FIELDS TERMINATED BY ','
LINES TERMINATED BY 'rn' -- or 'n'
IGNORE 1 LINES
(sha1, @var1, trendx)
SET vsdt = TRIM(TRAILING ')' FROM TRIM(LEADING '(' FROM @var1));


To make this call from your Python code, you may try something like this:



query = "LOAD DATA INFILE 'path/to/rb' INTO TABLE jeremy_table_test FIELDS TERMINATED BY ',' LINES TERMINATED BY 'rn' IGNORE 1 LINES (sha1, @var1, trendx) SET vsdt = TRIM(TRAILING ')' FROM TRIM(LEADING '(' FROM @var1))"
cursor.execute(query)
connection.commit()





share|improve this answer


























  • can you edit it in full code? I can't understand the formatting of load data infile, just a newbie here

    – Godshand
    Nov 15 '18 at 5:56











  • I don't understand your request. My answer is about as clear as it can be. You might want to try running LOAD DATA first from the command line, to make sure that there are no issues there. Then, once you are sure it works, try running it from your Python code.

    – Tim Biegeleisen
    Nov 15 '18 at 5:58











  • tried it but gives me ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IGNORE 1 LINES' at line 1

    – Godshand
    Nov 15 '18 at 6:09











  • great but how can i use load data using variable, my variable is like this: fullPath = mypath + "\" + theFile using fullPath

    – Godshand
    Nov 15 '18 at 6:18











  • I don't understand your question.

    – Tim Biegeleisen
    Nov 15 '18 at 6:25
















1














MySQL LOAD DATA tool can probably do what you want here. Here is what the LOAD DATA call might look like:



LOAD DATA INFILE 'path/to/rb'
INTO TABLE jeremy_table_test
FIELDS TERMINATED BY ','
LINES TERMINATED BY 'rn' -- or 'n'
IGNORE 1 LINES
(sha1, @var1, trendx)
SET vsdt = TRIM(TRAILING ')' FROM TRIM(LEADING '(' FROM @var1));


To make this call from your Python code, you may try something like this:



query = "LOAD DATA INFILE 'path/to/rb' INTO TABLE jeremy_table_test FIELDS TERMINATED BY ',' LINES TERMINATED BY 'rn' IGNORE 1 LINES (sha1, @var1, trendx) SET vsdt = TRIM(TRAILING ')' FROM TRIM(LEADING '(' FROM @var1))"
cursor.execute(query)
connection.commit()





share|improve this answer


























  • can you edit it in full code? I can't understand the formatting of load data infile, just a newbie here

    – Godshand
    Nov 15 '18 at 5:56











  • I don't understand your request. My answer is about as clear as it can be. You might want to try running LOAD DATA first from the command line, to make sure that there are no issues there. Then, once you are sure it works, try running it from your Python code.

    – Tim Biegeleisen
    Nov 15 '18 at 5:58











  • tried it but gives me ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IGNORE 1 LINES' at line 1

    – Godshand
    Nov 15 '18 at 6:09











  • great but how can i use load data using variable, my variable is like this: fullPath = mypath + "\" + theFile using fullPath

    – Godshand
    Nov 15 '18 at 6:18











  • I don't understand your question.

    – Tim Biegeleisen
    Nov 15 '18 at 6:25














1












1








1







MySQL LOAD DATA tool can probably do what you want here. Here is what the LOAD DATA call might look like:



LOAD DATA INFILE 'path/to/rb'
INTO TABLE jeremy_table_test
FIELDS TERMINATED BY ','
LINES TERMINATED BY 'rn' -- or 'n'
IGNORE 1 LINES
(sha1, @var1, trendx)
SET vsdt = TRIM(TRAILING ')' FROM TRIM(LEADING '(' FROM @var1));


To make this call from your Python code, you may try something like this:



query = "LOAD DATA INFILE 'path/to/rb' INTO TABLE jeremy_table_test FIELDS TERMINATED BY ',' LINES TERMINATED BY 'rn' IGNORE 1 LINES (sha1, @var1, trendx) SET vsdt = TRIM(TRAILING ')' FROM TRIM(LEADING '(' FROM @var1))"
cursor.execute(query)
connection.commit()





share|improve this answer















MySQL LOAD DATA tool can probably do what you want here. Here is what the LOAD DATA call might look like:



LOAD DATA INFILE 'path/to/rb'
INTO TABLE jeremy_table_test
FIELDS TERMINATED BY ','
LINES TERMINATED BY 'rn' -- or 'n'
IGNORE 1 LINES
(sha1, @var1, trendx)
SET vsdt = TRIM(TRAILING ')' FROM TRIM(LEADING '(' FROM @var1));


To make this call from your Python code, you may try something like this:



query = "LOAD DATA INFILE 'path/to/rb' INTO TABLE jeremy_table_test FIELDS TERMINATED BY ',' LINES TERMINATED BY 'rn' IGNORE 1 LINES (sha1, @var1, trendx) SET vsdt = TRIM(TRAILING ')' FROM TRIM(LEADING '(' FROM @var1))"
cursor.execute(query)
connection.commit()






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 6:03

























answered Nov 15 '18 at 5:54









Tim BiegeleisenTim Biegeleisen

229k1395147




229k1395147













  • can you edit it in full code? I can't understand the formatting of load data infile, just a newbie here

    – Godshand
    Nov 15 '18 at 5:56











  • I don't understand your request. My answer is about as clear as it can be. You might want to try running LOAD DATA first from the command line, to make sure that there are no issues there. Then, once you are sure it works, try running it from your Python code.

    – Tim Biegeleisen
    Nov 15 '18 at 5:58











  • tried it but gives me ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IGNORE 1 LINES' at line 1

    – Godshand
    Nov 15 '18 at 6:09











  • great but how can i use load data using variable, my variable is like this: fullPath = mypath + "\" + theFile using fullPath

    – Godshand
    Nov 15 '18 at 6:18











  • I don't understand your question.

    – Tim Biegeleisen
    Nov 15 '18 at 6:25



















  • can you edit it in full code? I can't understand the formatting of load data infile, just a newbie here

    – Godshand
    Nov 15 '18 at 5:56











  • I don't understand your request. My answer is about as clear as it can be. You might want to try running LOAD DATA first from the command line, to make sure that there are no issues there. Then, once you are sure it works, try running it from your Python code.

    – Tim Biegeleisen
    Nov 15 '18 at 5:58











  • tried it but gives me ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IGNORE 1 LINES' at line 1

    – Godshand
    Nov 15 '18 at 6:09











  • great but how can i use load data using variable, my variable is like this: fullPath = mypath + "\" + theFile using fullPath

    – Godshand
    Nov 15 '18 at 6:18











  • I don't understand your question.

    – Tim Biegeleisen
    Nov 15 '18 at 6:25

















can you edit it in full code? I can't understand the formatting of load data infile, just a newbie here

– Godshand
Nov 15 '18 at 5:56





can you edit it in full code? I can't understand the formatting of load data infile, just a newbie here

– Godshand
Nov 15 '18 at 5:56













I don't understand your request. My answer is about as clear as it can be. You might want to try running LOAD DATA first from the command line, to make sure that there are no issues there. Then, once you are sure it works, try running it from your Python code.

– Tim Biegeleisen
Nov 15 '18 at 5:58





I don't understand your request. My answer is about as clear as it can be. You might want to try running LOAD DATA first from the command line, to make sure that there are no issues there. Then, once you are sure it works, try running it from your Python code.

– Tim Biegeleisen
Nov 15 '18 at 5:58













tried it but gives me ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IGNORE 1 LINES' at line 1

– Godshand
Nov 15 '18 at 6:09





tried it but gives me ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IGNORE 1 LINES' at line 1

– Godshand
Nov 15 '18 at 6:09













great but how can i use load data using variable, my variable is like this: fullPath = mypath + "\" + theFile using fullPath

– Godshand
Nov 15 '18 at 6:18





great but how can i use load data using variable, my variable is like this: fullPath = mypath + "\" + theFile using fullPath

– Godshand
Nov 15 '18 at 6:18













I don't understand your question.

– Tim Biegeleisen
Nov 15 '18 at 6:25





I don't understand your question.

– Tim Biegeleisen
Nov 15 '18 at 6:25













2














Skip the row when you read it in, rather than when you write it.



with open(fullPath, 'rb') as file:
csv_data = csv.reader(file)
next(csv_data)
mycursor = mydb.cursor()
cursor = mydb.cursor()
for row in csv_data:
cursor.execute('INSERT INTO jeremy_table_test(sha1,vsdt,trendx)'
'VALUES(%s, %s, %s)',[(row[0]),(row[1]),(row[2]))
mydb.commit()
cursor.close()
print("Done")





share|improve this answer


























  • thanks, now my only problem is to delete the chars in my second column

    – Godshand
    Nov 15 '18 at 5:53






  • 1





    Can u explain why two different cursors are taken? Tough only 1 is used. And in next(csvreader) what is csvreader?

    – Shivam Seth
    Nov 15 '18 at 5:59











  • Yeah, to be honest I din't look at that part of the code, just cleaned up the bit OP asked about. There is no need for the lines referring to mydb.commit().

    – directive-41
    Nov 15 '18 at 6:36











  • @Godshand, just use string slicing to remove the unwanted characters if they are only the first and last, and are consistently present. E.g., row[1][1:] will drop the first character from your 2nd column value every time. If they are only present on some rows, then you will need something trickier, probably use regex.

    – directive-41
    Nov 15 '18 at 6:41













  • @ Shivam Seth, my bad typing is the reason for the error in next() - fixed now, thanks.

    – directive-41
    Nov 15 '18 at 6:47
















2














Skip the row when you read it in, rather than when you write it.



with open(fullPath, 'rb') as file:
csv_data = csv.reader(file)
next(csv_data)
mycursor = mydb.cursor()
cursor = mydb.cursor()
for row in csv_data:
cursor.execute('INSERT INTO jeremy_table_test(sha1,vsdt,trendx)'
'VALUES(%s, %s, %s)',[(row[0]),(row[1]),(row[2]))
mydb.commit()
cursor.close()
print("Done")





share|improve this answer


























  • thanks, now my only problem is to delete the chars in my second column

    – Godshand
    Nov 15 '18 at 5:53






  • 1





    Can u explain why two different cursors are taken? Tough only 1 is used. And in next(csvreader) what is csvreader?

    – Shivam Seth
    Nov 15 '18 at 5:59











  • Yeah, to be honest I din't look at that part of the code, just cleaned up the bit OP asked about. There is no need for the lines referring to mydb.commit().

    – directive-41
    Nov 15 '18 at 6:36











  • @Godshand, just use string slicing to remove the unwanted characters if they are only the first and last, and are consistently present. E.g., row[1][1:] will drop the first character from your 2nd column value every time. If they are only present on some rows, then you will need something trickier, probably use regex.

    – directive-41
    Nov 15 '18 at 6:41













  • @ Shivam Seth, my bad typing is the reason for the error in next() - fixed now, thanks.

    – directive-41
    Nov 15 '18 at 6:47














2












2








2







Skip the row when you read it in, rather than when you write it.



with open(fullPath, 'rb') as file:
csv_data = csv.reader(file)
next(csv_data)
mycursor = mydb.cursor()
cursor = mydb.cursor()
for row in csv_data:
cursor.execute('INSERT INTO jeremy_table_test(sha1,vsdt,trendx)'
'VALUES(%s, %s, %s)',[(row[0]),(row[1]),(row[2]))
mydb.commit()
cursor.close()
print("Done")





share|improve this answer















Skip the row when you read it in, rather than when you write it.



with open(fullPath, 'rb') as file:
csv_data = csv.reader(file)
next(csv_data)
mycursor = mydb.cursor()
cursor = mydb.cursor()
for row in csv_data:
cursor.execute('INSERT INTO jeremy_table_test(sha1,vsdt,trendx)'
'VALUES(%s, %s, %s)',[(row[0]),(row[1]),(row[2]))
mydb.commit()
cursor.close()
print("Done")






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 6:46

























answered Nov 15 '18 at 5:49









directive-41directive-41

989




989













  • thanks, now my only problem is to delete the chars in my second column

    – Godshand
    Nov 15 '18 at 5:53






  • 1





    Can u explain why two different cursors are taken? Tough only 1 is used. And in next(csvreader) what is csvreader?

    – Shivam Seth
    Nov 15 '18 at 5:59











  • Yeah, to be honest I din't look at that part of the code, just cleaned up the bit OP asked about. There is no need for the lines referring to mydb.commit().

    – directive-41
    Nov 15 '18 at 6:36











  • @Godshand, just use string slicing to remove the unwanted characters if they are only the first and last, and are consistently present. E.g., row[1][1:] will drop the first character from your 2nd column value every time. If they are only present on some rows, then you will need something trickier, probably use regex.

    – directive-41
    Nov 15 '18 at 6:41













  • @ Shivam Seth, my bad typing is the reason for the error in next() - fixed now, thanks.

    – directive-41
    Nov 15 '18 at 6:47



















  • thanks, now my only problem is to delete the chars in my second column

    – Godshand
    Nov 15 '18 at 5:53






  • 1





    Can u explain why two different cursors are taken? Tough only 1 is used. And in next(csvreader) what is csvreader?

    – Shivam Seth
    Nov 15 '18 at 5:59











  • Yeah, to be honest I din't look at that part of the code, just cleaned up the bit OP asked about. There is no need for the lines referring to mydb.commit().

    – directive-41
    Nov 15 '18 at 6:36











  • @Godshand, just use string slicing to remove the unwanted characters if they are only the first and last, and are consistently present. E.g., row[1][1:] will drop the first character from your 2nd column value every time. If they are only present on some rows, then you will need something trickier, probably use regex.

    – directive-41
    Nov 15 '18 at 6:41













  • @ Shivam Seth, my bad typing is the reason for the error in next() - fixed now, thanks.

    – directive-41
    Nov 15 '18 at 6:47

















thanks, now my only problem is to delete the chars in my second column

– Godshand
Nov 15 '18 at 5:53





thanks, now my only problem is to delete the chars in my second column

– Godshand
Nov 15 '18 at 5:53




1




1





Can u explain why two different cursors are taken? Tough only 1 is used. And in next(csvreader) what is csvreader?

– Shivam Seth
Nov 15 '18 at 5:59





Can u explain why two different cursors are taken? Tough only 1 is used. And in next(csvreader) what is csvreader?

– Shivam Seth
Nov 15 '18 at 5:59













Yeah, to be honest I din't look at that part of the code, just cleaned up the bit OP asked about. There is no need for the lines referring to mydb.commit().

– directive-41
Nov 15 '18 at 6:36





Yeah, to be honest I din't look at that part of the code, just cleaned up the bit OP asked about. There is no need for the lines referring to mydb.commit().

– directive-41
Nov 15 '18 at 6:36













@Godshand, just use string slicing to remove the unwanted characters if they are only the first and last, and are consistently present. E.g., row[1][1:] will drop the first character from your 2nd column value every time. If they are only present on some rows, then you will need something trickier, probably use regex.

– directive-41
Nov 15 '18 at 6:41







@Godshand, just use string slicing to remove the unwanted characters if they are only the first and last, and are consistently present. E.g., row[1][1:] will drop the first character from your 2nd column value every time. If they are only present on some rows, then you will need something trickier, probably use regex.

– directive-41
Nov 15 '18 at 6:41















@ Shivam Seth, my bad typing is the reason for the error in next() - fixed now, thanks.

– directive-41
Nov 15 '18 at 6:47





@ Shivam Seth, my bad typing is the reason for the error in next() - fixed now, thanks.

– directive-41
Nov 15 '18 at 6:47


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313098%2fskip-first-row-and-delete-certain-char-before-importing-csv-to-db%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

The Sandy Post

Danny Elfman

Pages that link to "Head v. Amoskeag Manufacturing Co."