Created
November 28, 2017 17:05
-
-
Save sourceperl/fb85525d7de443ee0c84ebb6438cf0a1 to your computer and use it in GitHub Desktop.
Display french RTE data to matplotlib with pandas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
import dateutil.parser | |
import requests | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import time | |
rte_raw_d = requests.get('https://opendata.reseaux-energies.fr/api/records/1.0/search/' | |
'?dataset=consommation-production-electricite-temps-reel&rows=96&sort=-date' | |
'&facet=date_heure&refine.date_heure=%s' % time.strftime('%Y-%m-%d')).json() | |
rte_df = pd.DataFrame([], columns=['conso', 'eolien', 'solaire']) | |
for record in rte_raw_d['records']: | |
if 'fields' in record: | |
dt = dateutil.parser.parse(record['fields']['date_heure']) | |
rte_df.loc[dt] = dict(conso=record['fields'].get('conso'), | |
eolien=record['fields'].get('eolien'), | |
solaire=record['fields'].get('solaire')) | |
rte_df.sort_index(inplace=True) | |
# print(rte_df.to_string()) | |
rte_df.plot() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment