Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 通过RESTAPI获取数据以及如何将其存储到mysql数据库?_Python_Mysql_Pandas_Web Scraping_Restapi - Fatal编程技术网

Python 通过RESTAPI获取数据以及如何将其存储到mysql数据库?

Python 通过RESTAPI获取数据以及如何将其存储到mysql数据库?,python,mysql,pandas,web-scraping,restapi,Python,Mysql,Pandas,Web Scraping,Restapi,我只是通过RESTAPI获取数据,并希望将其保存在mysql数据库中。作为一名初学者,我正在寻找一种将数据保存到sql数据库中的方法。你们能给我推荐一些教程/图书馆/例子吗。那将是很大的帮助。谢谢如果我反对stackoverflow条款,我真的很抱歉。但在这个话题上我真的需要帮助 **from entsoe import EntsoePandasClient import pandas as pd client = EntsoePandasClient(api_key='api-key')

我只是通过RESTAPI获取数据,并希望将其保存在mysql数据库中。作为一名初学者,我正在寻找一种将数据保存到sql数据库中的方法。你们能给我推荐一些教程/图书馆/例子吗。那将是很大的帮助。谢谢如果我反对stackoverflow条款,我真的很抱歉。但在这个话题上我真的需要帮助

**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)**
使用pandas提供的函数,您只需传递使用SQLAlchemy库创建的连接对象:

从sqlalchemy导入创建引擎 engine=创建_enginemysql+pymysql://root:pass@localhost/mydb df.to_sql'table_name_for_df',con=engine,如果_exists='append',flavor='mysql' 检查数据是否已发送 engine.executeSELECT*从表\u name\u中为\u df.fetchall选择