import mysql.connector
import openpyxl
# Open the .xlsx file
wb = openpyxl.load_workbook('data.xlsx')
sheet = wb.active
# Connect to the MySQL database
cnx = mysql.connector.connect(user='user', password='password', host='host', database='database')
cursor = cnx.cursor()
# Validate and import the data
for row in sheet.rows:
# Validate each cell in the row
if row[0].value == None:
print("Error: Missing value in column 1")
elif row[1].value == None:
print("Error: Missing value in column 2")
else:
# If the data is valid, insert it into the database
sql = "INSERT INTO table (column1, column2) VALUES (%s, %s)"
val = (row[0].value, row[1].value)
cursor.execute(sql, val)
# Commit the changes to the database
cnx.commit()
# Close the connection
cnx.close()
Showing posts with label mysql and validate also each column and rows before import. Show all posts
Showing posts with label mysql and validate also each column and rows before import. Show all posts
Tuesday, January 3, 2023
python code to import xlsx file in mysql and validate also each column and rows before import
Subscribe to:
Posts (Atom)
can you please explain me Backpropagation & Gradients in layman language as simple as possible
Absolutely! Let’s break down backpropagation and gradients in the simplest possible way , like we’re teaching a curious 10-year-old. 🎯...
-
The error message you encountered ("DeleteService FAILED 1072: The specified service has been marked for deletion") indicates tha...
-
may be you need to show serial number in your rdlc report then you can use following syntax for showing 1,2,3... continuous on in table fie...
-
Transformers have shown promising results in various natural language processing (NLP) tasks, but they can also be adapted for time series ...