Install Python 3.7
Installing packages for windows
C:\Users\username>pip
install mysql-connector-python
Collecting
mysql-connector-python
Downloading https://files.pythonhosted.org/packages/bc/5c/abd95d9d978982e669d5caa7b40d86efce01e9729800043e40581b6e55f5/mysql_connector_python-8.0.18-py2.py3-none-any.whl
(346kB)
|████████████████████████████████| 348kB 2.2MB/s
Collecting
protobuf>=3.0.0 (from mysql-connector-python)
Downloading https://files.pythonhosted.org/packages/ad/c2/86c65136e280607ddb2e5dda19e2953c1174f9919b557d1d154574481de4/protobuf-3.10.0-py2.py3-none-any.whl
(434kB)
|████████████████████████████████| 440kB ...
Requirement already
satisfied: setuptools in
c:\users\mhossai5\appdata\local\programs\python\python38\lib\site-packages
(from protobuf>=3.0.0->mysql-connector-python) (41.2.0)
Collecting
six>=1.9 (from protobuf>=3.0.0->mysql-connector-python)
Installing collected
packages: six, protobuf, mysql-connector-python
Successfully
installed mysql-connector-python-8.0.18 protobuf-3.10.0 six-1.12.0
WARNING: You are
using pip version 19.2.3, however version 19.3 is available.
You should consider
upgrading via the 'python -m pip install --upgrade pip' command.
UPGARDE PIP
python -m pip
install --upgrade pip
import sys
print(sys.version_info)
PROGRAM CONNECTION TO MYSQL
# Author:
#
# Created: 14/10/2019
# Copyright: (c) MHossai5 2019
# Licence: <your licence>
#-------------------------------------------------------------------------------
def main():
pass
if __name__ ==
'__main__':
main()
import
mysql.connector
from mysql.connector
import Error
try:
connection =
mysql.connector.connect(host='localhost',
database='test',
user='root',
password='')
if connection.is_connected():
db_Info = connection.get_server_info()
print("Connected to MySQL Server
version ", db_Info)
cursor = connection.cursor()
cursor.execute("select
database();")
record = cursor.fetchone()
print("Your connected to database:
", record)
except Error as e:
print("Error while connecting to
MySQL", e)
finally:
if (connection.is_connected()):
cursor.close()
connection.close()
print("MySQL connection is
closed")
PROGRAM WITH PANDAS
import pandas as pd
from pandas import
DataFrame
Cars = {'Brand':
['Honda Civic','Toyota Corolla','Ford Focus','Audi A4'],
'Price': [32000,35000,37000,45000]
}
df = DataFrame(Cars,
columns= ['Brand', 'Price'])
export_excel =
df.to_excel (r'C:\Users\user\Desktop\export_dataframe4.xlsx', index = None,
header=True) #Don't forget to add '.xlsx' at the end of the path
print (df)
import
matplotlib.pyplot as plt
#df =
pd.read_csv("export_dataframe4.csv")
dn =
pd.read_excel(r"C:\Users\user\Desktop\export_dataframe4.xlsx")
dn.plot()
plt.show()
PROGRAM WITH METHODS
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author:
#
# Created: 16/10/2019
# Copyright: 2019
# Licence: <your licence>
#-------------------------------------------------------------------------------
def main():
pass
if __name__ ==
'__main__':
main()
my_list = [1,2,3]
squaresl = [num*num for num in my_list]
print(squaresl)
myl_list = [1,2,3]
for num in myl_list:
squarepl = (num*num)
print(squarepl)
def my_function(x):
return x[::-1]
mytxt =
my_function("this text will look like backwards")
print(mytxt)
def fun_fib():
a,b=0,1
for i in range(6):
a,b=b,a+b
print (a,b)
fun_fib()
MySQL DB connection
https://www.geeksforgeeks.org/mysqldb-connection-python/
https://www.w3schools.com/python/python_mysql_getstarted.asp
https://pynative.com/install-mysql-connector-python/
https://pynative.com/python-mysql-select-query-to-fetch-data/




