This article illustrates the basic operation of how the dataset imported from the table. The database is taken as MySQL.

Is database is an essential thing for DataScience?

Yes, It is an essential thing. Without the data, the data analysis and forecasting can’t be done. Right!. The data can be any kind of format that may be in CSV, XLS. Consider the retail organization selling their multiple products from the past 5 years. The company decided to forecast the prediction of sales for the next two years.

I grasped what you thinking? Basically, try the data export to CSV file. That can be easily handled in the pandas data frame. But the things not working in such way because prediction does not rely on a single table. It depends on multiple tables say transaction, sales, customer review, the revenue of product from 5 years those need to look in to determine the prediction. The best-opted way will be directly importing the table to the data frame. That will be easier for analysis data against all perspectives.

To connect MySQL using pandas, need to install package ‘mysql-connector-python’ as below command.

pip install mysql-connector-python

For reference

Image for post

Package installation console

import mysql.connector as connection
import pandas as pd

try:
    mydb = connection.connect(host="localhost", database = 'Student',user="root", passwd="root",use_pure=True)
    query = "Select * from studentdetails;"
    result_dataFrame = pd.read_sql(query,mydb)
    mydb.close() #close the connection
except Exception as e:
    mydb.close()
    print(str(e))

#mysql #pandas-dataframe

Importing data from a MySQL database into Pandas data frame
1.40 GEEK