Till now, I've been requesting data from my SQL-server, using an API, php file basically and using the requests module in Python. So here's my code for that:
# importing the requests library
import requests
# api-endpoint
URL = "https://******.co.in/******/queryRandom.php"
# location given here
token= '***************'
query= 'SELECT userId,createdAt,.... FROM xyz WHERE date >= CURDATE() - INTERVAL 60 DAY'
# defining a params dict for the parameters to be sent to the API
PARAMS = {'token':token, 'query':query}
# sending get request and saving the response as response object
r = requests.post(url = URL, data = PARAMS)
df=pd.DataFrame(r.json())
df.head()
Now after I'm done with my work, I formed a dataframe like this:
Sl.No. date nameofthepic
1 26-08-2018 10-must-see-waterfalls-in-karnataka-8081714182d8
2 26-08-2018 a-month-in-backpack-one-girl-one-goal-to-explore-the-himalayas-22813ee67e15
3 26-08-2018 a-month-in-backpack-one-girl-one-goal-to-explore-the-himalayas-week-1-8d113ee673db
4 26-08-2018 a-month-in-backpack-one-girl-one-goal-to-explore-the-himalayas-week-1-22b13ee67b87
5 26-08-2018 backpacking-for-a-month-in-the-himalayas-week-1-30813ee674a6
Now using the similar requests module, is there a way I can write something like this: INSERT INTO table_name... and upload the dataframe into the SQL table.
The main problem I'm not able to figure out is:
i) How do I upload the dataframe column values into the table in one go?
ii) If its not possible through requests module, is there any other way I can upload the Pandas dataframe values into SQL-server table directly from jupyter-notebook using Python code?