I want to connect my company's SQL database with python to pull the data and paste it in a dataframe. Is it possible. could you please help me with sample code
CodePudding user response:
There is not much detail in your question, so I will tell the steps.
- You will need to install a driver or a module (like
pyodbc
ormysql-sql-connector-python
). This is to help python app interact with an SQL application. - Now you will have to create an instance of connection with appropriate login credentials and the database name you want to connect to.
- Finally you can read the data onto dataframe directly by using
pandas.read_sql(query, conn)
.
This link I hope will help you with sample snippet and more details