Hey. I am trying to upload data to my MYSQL table from the CSV file. My mysql table looks like:
and my CSV is as following:
I am not very experienced with python, but I have tried a few example codes:
First of all, I do not think I properly understand how pandas.read_csv works as in how does it return data?
returns me what I expect:
However,
returns me:
Item
Serial
Quantity
which is strange, since It outputs me a collum names, instead of rows. Could someone give me some hints here?
and my CSV is as following:
I am not very experienced with python, but I have tried a few example codes:
Code:
import pandas as pd
import mysql.connector
hostname = 'localhost'
username = 'root'
password = 'pswd'
database = 'test'
myConnection = mysql.connector.connect( host=hostname, user=username, passwd=password, db=database )
#cur = myConnection.cursor()
data = pd.read_csv("rut1.csv")
print(data)
for row in data:
print(row)
#print(row[1])
#print(row[2])
#myConnection = mysql.connector.connect( host=hostname, user=username, passwd=password, db=database )
#cur = myConnection.cursor()
#cur.execute("REPLACE INTO komplektacija(Item,Serial,Quantity) VALUES(%s, %s, %i)",row)
#cur.execute("REPLACE INTO komplektacija(Item,Serial,Quantity) VALUES(%s, %s, %i);" % (row[],row[2],row[3]))
#myConnection.commit()
#cur.close()
Code:
data = pd.read_csv("rut1.csv")
print(data)
However,
Code:
for row in data:
print(row)
Item
Serial
Quantity
which is strange, since It outputs me a collum names, instead of rows. Could someone give me some hints here?
Attachments
-
234.6 KB Views: 0
-
215.3 KB Views: 0
-
215.6 KB Views: 0