Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Data Analysis and Visualization with MariaDB Connector/Python

The samples contained in this directory demonstrate how to use MariaDB Connector/Python in combination with libraries Plotly and Pandas to analyze and visualize data.

Note: This directory assumes that you've already installed the necessary requirements for using MariaDB Connector/Python. If you haven't, please refer to the root README of this repository.

Downloading and loading data

The samples in this directory rely on flight data that is available from the United States Bureau of Transport. For more information on database preparation make sure you check out the following repository before continuing:

Getting started

There are two ways to utilize MariaDB Connector/Python with Plotly and Pandas in this directory. Both options contain the same examples.

  1. By executing the Python code files directly.
  2. By using Jupyter Lab to facilitate the code development, execution, and visualization.

Prepare virtual environment

Regardless of which option you choose you will need to do the following to prepare a suitable enviroment.

  1. Open a new terminal at this location and create a new virtual environment using the following command:

    $ python3 -m venv demo
  2. Activate the virtual environment.

    $ . demo/bin/activate

Using Python files directly

  1. Download and install the necessary Python packages.

    $ pip install mariadb plotly pandas
  2. Update the connection configuration in the demo files to point to a valid database instance.

    For example:

    config = {
        'host': 'analytics-demo.mdb0001390.db.skysql.net',
        'port': 5001,
        'user': 'DB00004088',
        'password': 'Password123!,
        'database': 'travel',
        'ssl': True
    }
  3. Execute the demo files.

    $ python src/demo_1.py
    $ python src/demo_2.py
    $ python src/demo_3.py
    $ python src/demo_4.py

    Demo_1 will output directly to the terminal, while Demo_2/3/4 will display a chart within your default browser.

Using Jupyter Lab

  1. Download and install the necessary Python packages.

    $ pip install mariadb plotly pandas jupyterlab
  2. Install Jupyter extension to facilitate Plotly rendering.

    $ jupyter labextension install jupyterlab-plotly@4.14.3
  3. Run Jupyter Lab.

    $ jupyter lab
  4. Open Demo.ipynb (a Jupyter Notebook file).

7.) Select and Jupyter Notebook cell and run.

Note: Make sure you update the connection configuration!