[英]Getting data through REST API and how to store it mysql database?
I just got the data through REST API and wanted to save it in mysql database.我刚刚通过 REST API 获取数据,并想将其保存在 mysql 数据库中。 As I'm a beginner, just looking a way to save the data into my sql database.
由于我是初学者,只是在寻找一种将数据保存到我的 sql 数据库中的方法。 Could you guys please suggest me some tutorial/library/example.
你们能给我推荐一些教程/库/示例吗? That would be great help.
那将是很大的帮助。 Thanks.
谢谢。 And if I'm against the stackoverflow terms and condition, I'm really sorry that.
如果我反对 stackoverflow 的条款和条件,我真的很抱歉。 But I need really help on this topic.
但我真的需要关于这个话题的帮助。
**from entsoe import EntsoePandasClient
import pandas as pd
client = EntsoePandasClient(api_key='api-key')
start = pd.Timestamp('20171201', tz='Europe/Brussels')
end = pd.Timestamp('20180101', tz='Europe/Brussels')
country_code = 'BE' # Belgium
# methods that return Pandas Series
client.query_day_ahead_prices(country_code, start=start,end=end)
client.query_load(country_code, start=start,end=end)
client.query_load_forecast(country_code, start=start,end=end)
client.query_generation_forecast(country_code, start=start,end=end)
# methods that return Pandas DataFrames
client.query_wind_and_solar_forecast(country_code, start=start,end=end, psr_type=None)
client.query_generation(country_code, start=start,end=end, psr_type=None)
client.query_installed_generation_capacity(country_code, start=start,end=end, psr_type=None)
client.query_crossborder_flows('DE', 'DK', start=start,end=end)
client.query_imbalance_prices(country_code, start=start,end=end, psr_type=None)
client.query_unavailability_of_generation_units(country_code, start=start,end=end, docstatus=None)
#client.query_withdrawn_unavailability_of_generation_units('DE', start=start,end=end)
ts = client.query_day_ahead_prices(country_code, start=start, end=end)
print(ts)**
Using to_sql
function provided by pandas all u need is to pass a connection object created with the SQLAlchemy
library :使用
to_sql
提供的to_sql
函数,您只需要传递一个使用SQLAlchemy
库创建的连接对象:
from sqlalchemy import create_engine
engine = create_engine("mysql+pymysql://root:pass@localhost/mydb")
df.to_sql('table_name_for_df', con=engine, if_exists='append', flavor='mysql')
# check if the data has been sent
engine.execute("SELECT * FROM table_name_for_df").fetchall()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.