MySQL Python/Connector is an interface for connecting to a MySQL database server from Python. It implements the Python Database API and is built on top of MySQL.

For installing MySQL-connector-python first you have to open your terminal and execute the following code

pip install mysql-connector-python

After installation, you have to import that package into your code and define your database name and other entities using connect().

You can establish a connection using the connect() constructor. This accepts the username, password, host and, name of the database you need to connect with (optional) and, returns an object of the MySQLConnection class.


MySQL is an open-source relational database management system based on SQL — Structured Query Language. The application is used for a wide range of purposes, including data warehousing, e-commerce, and logging applications. The most common use for MySQL however, is for the purpose of a web database.

Database

show

To view all the existing databases you can use the below syntax

show databases;

In this story, we are gonna see some questions on manipulation of some student's data and the solution will be composed of various python libraries such as pandas, regex, and numpy.

Question

Consider,

data=pd.DataFrame({‘names’:[‘tom’,’sam’,…],’email’:[‘tom21@gmail.com’,’samdr@yahoo.com’,’jk21456@abc.com’,..],’Firstweekscore’:[],’secondweekscore:[]})

1.Write a function that will create a new column consisting of an average of two scores

2.List comprehension → create another column which is consisting of scores 93 → 96

3.’gmail.com’ →regular expressions in pandas

4.Select rows which are having gmail address and also secondtestscore greater than 90

5.Create a new column ‘group’ and randomly assign values as 1,2 and 3

6.Create a pivot table having means…


Pandas is a software library written for the Python programming language. It is used for data manipulation and analysis. In particular, it offers data structures and operations for manipulating numerical tables and time series.

Installation

We can install pandas by entering the following line of code in our command prompt. We have to import it every time we use it like every other predefined module in Python.

pip install pandas        #Installationimport pandas as pd       #Importing

Data structures

Unlike NumPy, pandas has three data structures based on the array’s dimension, They are:

  1. Series
  2. Data Frames
  3. panel

Among the above three data structures, panel…


NumPy stands for Numerical Python. NumPy is an open-source numerical Python library. NumPy contains a multi-dimensional array and matrix data structures. It can be utilized to perform a number of mathematical operations on arrays such as trigonometric, statistical, and algebraic routines.

Installation

We can install NumPy by entering the following line of code in our command prompt and we have to import it every time we use it like every other predefined module in python

pip install numpyimport numpy as np 

Data structure in numpy

Unlike python, the only data structure in the numpy is an array, and that array can support only one…


Abstraction in Python is the process of hiding the real implementation of an application from the user and emphasizing only how to use the application.

An abstract method is also known as an incomplete method where we can only implement it in the children's classes.

How Abstract Base classes work :

By default, Python does not provide abstract classes. Python comes with a module that provides the base for defining Abstract Base classes(ABC) and that module name is ABC. ABC works by decorating methods of the base class as abstract and then registering concrete classes as implementations of the abstract base. …


A RegEx, or Regular Expression, is a sequence of characters that forms a search pattern.RegEx can be used to check if a string contains the specified search pattern.

In python, RegEx can be used from a module called re, which must be imported in order to work with the regular expressions.

import re

There are many keyword patterns used in RegEx in order to form a search pattern, you can have a brief look at them on RegexOne.

Match

The match function is used to check whether the given pattern matches with the strings at the beginning of the string.

import…

Python super() function is used for accessing the methods and properties of the base class or superclass, basically a super function returns a proxy object.

For example:

class Person:
def __init__(self,name,age):
self.name = name
self.age = age
class Student(Person):
def __init__(self,name,age,grade):
super().__init__(name,age)
self.grade = grade
def printGrade(self):
print('Student name is {} age is{} and Grade is{}'.format(self.name,self.age,self.grade))
stud1 = Student('tom',24,'A')
stud1.printGrade()
Student name is tom age is 24 and Grade is A

From the above program, we can see that we have used the instances of the parent class in the child class using the super keyword, like this we can…


There are different types of methods are there while defining a class, they are

  1. Instance method
  2. Class method
  3. Static method

Instance Method

Instance attributes are those attributes that are not shared by objects. Every object has its own copy of the instance attribute, let us see an example

class Student:
def __init__(self,name):
self.name = name
def printinfo(self):
self.city = 'delhi'
print('my name is {} and from {}'.format(self.name,self.city))
def printcity(self):
print('my city is ', self.city)
stud1 = Student('tom')
stud1.printinfo()
my name is tom and from delhi

class method

It is one of the rarely used methods, where we use cls instead of self and we…


Inheritance allows us to define a class that takes all the functionality from a parent class and allows us to add more. The parent class is the class being inherited from, also called a base class. The child class is the class that inherits from another class, also called derived class.

Let us see an example:

class Student:
def__init__(self,name,rollno,marks):
self.name = name
self.rollno = rollno
self.marks = marks
def Info(self):
print('Student name is ',self.name,'roll no ',self.rollno)
class Result(Student):
def res(self):
if(self.marks>50):
print("pass")
else:
print("Fail")

In the above program, the Student class is the parent class and the Result class is…

Nandhabalan Marimuthu

Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store