Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.7k views
in Technique[技术] by (71.8m points)

sqlite - Python sqlite3. Writing to a table from pandas read_csv results in error: Incomplete input

I'm running on Python 3.8 and have the following code:

conn = sqlite3.connect('feedback.db')  
c = conn.cursor()

read_feedback = pd.read_csv (r'C:jupfeedback.csv', parse_dates=['Created'])

read_feedback.to_sql('FEEDBACK_IN', conn, if_exists='append', index = False) # Insert the values from the csv file into the table 'FEEDBACK_IN' 

c.execute('''INSERT INTO FEEDBACK_IN (Feedback, Created, User)''')`

The table has been created using this code:

c.execute('''CREATE TABLE FEEDBACK_IN
             ([generated_id] INTEGER PRIMARY KEY,[Feedback] text, [Created] date, [User] text)''')

The sample from the csv:

Feedback,Created,User Quick help. Thank you!,29/12/2020,[email protected]

The dataframe from csv looks ok:

                                         Feedback    Created                   User

0 Quick help. Thank you! 2020-12-29 [email protected]

When I reach c.execute('''INSERT INTO FEEDBACK_IN (Feedback, Created, User)''') I get get an error thrown:

----> 1 c.execute('''INSERT INTO FEEDBACK_IN (Feedback, Created, User)''') OperationalError: incomplete input

I have played with the date formats, sequence of fields, now lost.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...