Recently, I started working on a Power BI project where I am using Python for data preparation and database transformations. This is a completely new experience for me, and I’m really excited to explore this space. Through this project, I’ve already started learning how data flows from a database to analytics tools like Power BI, and how backend processing plays a crucial role in building reliable dashboards.
In this blog, I’ll walk you through the end-to-end setup, including prerequisites, database creation, and Python integration with MySQL.
Install MYSQL
Install Python
Install Visual Studio Code
Create Database
Create Table
In order to connect with Database, Python need MYSQL-connector-python package
if install : show install successfully ! if you does not put path in environment variable. otherwise you will give Error
Open Visual Studio
create file mysql_connect_python.py with py extension
Note: extension: py (it is very important otherwise program can not run)
fetchone() - returns only one row
fetchall() - returns all rows as a list of tuples
When working on my project with Power BI, I realized that just using SQL queries is not always enough. For better data cleaning and transformation, I started using Pandas in Python.
Convert database data into a table format (DataFrame)
Clean and filter data easily
Handle large datasets
Prepare data for Power BI
In order to work with MySQL data and prepare it for Power BI, Python needs the Pandas package.
Note: install : show install successfully ! if you does not put path in environment variable. otherwise you will give Error
After installing Pandas, Imported the required libraries in Python.
mysql.connector - to connect Python with MySQL
pandas - to work with data in table format (DataFrame)
If you have MYSQL database file and want to read it in Python using Pandas, you can do.
df - Contains all the data from the file in table format.
pd.read_sql() - pandas function used to directly fetch data from a SQL database into a DataFrame.
connection - MYSQL connection object
First, I connected Python to MySQL using mysql-connector-python. Then, I got the data from the database and put it into a Pandas DataFrame. This made it very easy to read, clean, and prepare the data for analysis or for visualization tools like Power BI.
create file mysql_connect_python.py with py extension
Well using this project i learn many new thing like how mysql-connector and pandas libraries help us in data cleaning and setting up transformation rules. and i create one Github Repository .
Kindly Refer my Github Repository link :
https://github.com/aavijaywx/CSV-PANDAS-MYSQL-INTEGRATION.git