How to take rows in csv file and use them as values for columns in table?












0















Write a function named "csv_to_db" that takes a string as a parameter representing the name of a csv file and doesn't return a value. There is a database saved in a file named "port.db" containing a table named "introduce" with columns "luck", "reportedly", and "isolate". Read the csv file with the name equal to the input string and add each row of this file as a record in the table. Each row in the csv file will contain 3 strings as its values which should be used as the values for the three columns in the table.



import sqlite3
import csv
def csv_to_db(string):
conn = sqlite3.connect('port.db')
with open(string, 'r') as f:
reader = csv.reader(f)
for row in reader:
c = conn.cursor()
insert = c.executemany('INSERT INTO introduce VALUES (?, ?, ?)', row)
conn.commit()


Here is my attempt at the question; getting error: The current statement uses 3, and there are 10 supplied. How can I fix this?










share|improve this question























  • No need to write any code: sqlite.org/cli.html#csv_import

    – Shawn
    Nov 24 '18 at 20:40











  • What do you mean?

    – user10649535
    Nov 24 '18 at 20:56











  • Possible duplicate of Importing a CSV file into a sqlite3 database table using Python

    – stovfl
    Nov 24 '18 at 21:00











  • Read the link. The sqlite3 shell can import CSV files into tables for you. No need to write your own code for a trivial case like this. sqlite3 -csv port.db '.import your_file.csv introduce'

    – Shawn
    Nov 24 '18 at 21:10


















0















Write a function named "csv_to_db" that takes a string as a parameter representing the name of a csv file and doesn't return a value. There is a database saved in a file named "port.db" containing a table named "introduce" with columns "luck", "reportedly", and "isolate". Read the csv file with the name equal to the input string and add each row of this file as a record in the table. Each row in the csv file will contain 3 strings as its values which should be used as the values for the three columns in the table.



import sqlite3
import csv
def csv_to_db(string):
conn = sqlite3.connect('port.db')
with open(string, 'r') as f:
reader = csv.reader(f)
for row in reader:
c = conn.cursor()
insert = c.executemany('INSERT INTO introduce VALUES (?, ?, ?)', row)
conn.commit()


Here is my attempt at the question; getting error: The current statement uses 3, and there are 10 supplied. How can I fix this?










share|improve this question























  • No need to write any code: sqlite.org/cli.html#csv_import

    – Shawn
    Nov 24 '18 at 20:40











  • What do you mean?

    – user10649535
    Nov 24 '18 at 20:56











  • Possible duplicate of Importing a CSV file into a sqlite3 database table using Python

    – stovfl
    Nov 24 '18 at 21:00











  • Read the link. The sqlite3 shell can import CSV files into tables for you. No need to write your own code for a trivial case like this. sqlite3 -csv port.db '.import your_file.csv introduce'

    – Shawn
    Nov 24 '18 at 21:10
















0












0








0








Write a function named "csv_to_db" that takes a string as a parameter representing the name of a csv file and doesn't return a value. There is a database saved in a file named "port.db" containing a table named "introduce" with columns "luck", "reportedly", and "isolate". Read the csv file with the name equal to the input string and add each row of this file as a record in the table. Each row in the csv file will contain 3 strings as its values which should be used as the values for the three columns in the table.



import sqlite3
import csv
def csv_to_db(string):
conn = sqlite3.connect('port.db')
with open(string, 'r') as f:
reader = csv.reader(f)
for row in reader:
c = conn.cursor()
insert = c.executemany('INSERT INTO introduce VALUES (?, ?, ?)', row)
conn.commit()


Here is my attempt at the question; getting error: The current statement uses 3, and there are 10 supplied. How can I fix this?










share|improve this question














Write a function named "csv_to_db" that takes a string as a parameter representing the name of a csv file and doesn't return a value. There is a database saved in a file named "port.db" containing a table named "introduce" with columns "luck", "reportedly", and "isolate". Read the csv file with the name equal to the input string and add each row of this file as a record in the table. Each row in the csv file will contain 3 strings as its values which should be used as the values for the three columns in the table.



import sqlite3
import csv
def csv_to_db(string):
conn = sqlite3.connect('port.db')
with open(string, 'r') as f:
reader = csv.reader(f)
for row in reader:
c = conn.cursor()
insert = c.executemany('INSERT INTO introduce VALUES (?, ?, ?)', row)
conn.commit()


Here is my attempt at the question; getting error: The current statement uses 3, and there are 10 supplied. How can I fix this?







python database sqlite csv






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 20:25







user10649535




















  • No need to write any code: sqlite.org/cli.html#csv_import

    – Shawn
    Nov 24 '18 at 20:40











  • What do you mean?

    – user10649535
    Nov 24 '18 at 20:56











  • Possible duplicate of Importing a CSV file into a sqlite3 database table using Python

    – stovfl
    Nov 24 '18 at 21:00











  • Read the link. The sqlite3 shell can import CSV files into tables for you. No need to write your own code for a trivial case like this. sqlite3 -csv port.db '.import your_file.csv introduce'

    – Shawn
    Nov 24 '18 at 21:10





















  • No need to write any code: sqlite.org/cli.html#csv_import

    – Shawn
    Nov 24 '18 at 20:40











  • What do you mean?

    – user10649535
    Nov 24 '18 at 20:56











  • Possible duplicate of Importing a CSV file into a sqlite3 database table using Python

    – stovfl
    Nov 24 '18 at 21:00











  • Read the link. The sqlite3 shell can import CSV files into tables for you. No need to write your own code for a trivial case like this. sqlite3 -csv port.db '.import your_file.csv introduce'

    – Shawn
    Nov 24 '18 at 21:10



















No need to write any code: sqlite.org/cli.html#csv_import

– Shawn
Nov 24 '18 at 20:40





No need to write any code: sqlite.org/cli.html#csv_import

– Shawn
Nov 24 '18 at 20:40













What do you mean?

– user10649535
Nov 24 '18 at 20:56





What do you mean?

– user10649535
Nov 24 '18 at 20:56













Possible duplicate of Importing a CSV file into a sqlite3 database table using Python

– stovfl
Nov 24 '18 at 21:00





Possible duplicate of Importing a CSV file into a sqlite3 database table using Python

– stovfl
Nov 24 '18 at 21:00













Read the link. The sqlite3 shell can import CSV files into tables for you. No need to write your own code for a trivial case like this. sqlite3 -csv port.db '.import your_file.csv introduce'

– Shawn
Nov 24 '18 at 21:10







Read the link. The sqlite3 shell can import CSV files into tables for you. No need to write your own code for a trivial case like this. sqlite3 -csv port.db '.import your_file.csv introduce'

– Shawn
Nov 24 '18 at 21:10














0






active

oldest

votes











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%2f53462066%2fhow-to-take-rows-in-csv-file-and-use-them-as-values-for-columns-in-table%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown
























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f53462066%2fhow-to-take-rows-in-csv-file-and-use-them-as-values-for-columns-in-table%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

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen