09.10.2023 Views

Advanced Data Analytics Using Python_ With Machine Learning, Deep Learning and NLP Examples ( 2023)

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 2

ETL with Python (Structured Data)

except:

# Rollback in case there is any error

db.rollback()

# disconnect from server

db.close()

COMMIT Operation

The commit operation provides its assent to the database to finalize the

modifications, and after this operation, there is no way that this can be

reverted.

ROLL-BACK Operation

If you are not completely convinced about any of the modifications and you

want to reverse them, then you need to apply the roll-back() method.

The following is a complete example of accessing MySQL data through

Python. It will give the complete description of data stored in a CSV file or

MySQL database.

import MySQLdb

import sys

out = open('Config1.txt','w')

print "Enter the Data Source Type:"

print "1. MySql"

print "2. Text"

print "3. Exit"

while(1):

data1 = sys.stdin.readline().strip()

if(int(data1) == 1):

28

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!