You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"<a href=\"https://colab.research.google.com/github/Animeshcoder/MySQL-Python/blob/main/Python_MySQL_P3.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
27
+
]
28
+
},
29
+
{
30
+
"cell_type": "markdown",
31
+
"source": [
32
+
"### **Introduction:**\n",
33
+
"This project demonstrates how to use Pandas, SQLAlchemy, and PyMySQL to extract data from one MySQL database, manipulate it using Pandas, and save it to another MySQL database. The script includes logic for transforming and manipulating data to match the structure of a destination table, as well as checking if data already exists before saving it. In simple way you can understand that if values of column are stored in one database and it is storing that column data to the different columns of another database row wise."
"The first part of the script sets up the dependencies and connection details for the MySQL databases. The pandas module is imported as pd, the create_engine function is imported from the sqlalchemy module, and the urllib.parse module is imported. The password for the MySQL server is defined and URL-encoded using the quote function from the urllib.parse module to ensure that it can be safely included in a connection string. An engine object is then created using the create_engine function from SQLAlchemy, which represents a connection to the old MySQL database.\n",
91
+
"\n",
92
+
"Next, an SQL query is defined that selects all rows from the oldtable table in the olddatabase database where the value of the id column is greater than '363000'. This query is used to extract the data that will be saved to the new database. The read_sql_query function from Pandas is used to execute this query on the old MySQL database and store the result in a DataFrame.\n",
93
+
"\n",
94
+
"The script then selects a specific column (\"Value\") from the DataFrame and stores it in a new variable (column_data). This column data is then transformed into multiple columns by transposing it using the .T attribute. The columns of this transposed data are then renamed to match the column names in the destination table in the new database.\n",
95
+
"\n",
96
+
"A new engine object is created that represents a connection to the new MySQL database. The script then checks if the data already exists in this new database by reading data from the mytable table using the read_sql_table function from Pandas and comparing it to the transformed column data using the .equals method. If the data does not already exist in the new database, it is saved to a new table named newtable using the .to_sql method of the DataFrame object."
0 commit comments