0

I'd like to access a data structure which looks like this below. "key" is obviously the key here. So I'm expecting to be able to write something like EnergyData["key"]["en"]["Import Balance"][0] to access the first number stored in the list of values. But how do I type this, and how do I interpret this data structure? It's a list, with dict elements and then a list with data?

EnergyData
[{'key': [{'en': 'Import Balance',
        'de': 'Import Saldo',
        'fr': 'Solde des importations',
        'it': 'Saldo del Importazione'}],
      'color': 'rgb(125,25,125)',
      'chartType': 'multiChart',
      'chartTitle': [{'en': 'Electricity production and spot prices in Germany in 2019',
        'de': 'Stromproduktion und Börsenstrompreise in Deutschland in 2019',
        'fr': "Production électrique et prix d'échange (spot) de l'électricité en Allemagne en 2019",
        'it': 'La produzione di elettricità e spot price in Germania in 2019'}],
      'xAxisFormat': 'unixTime',
      'xAxisLabel': [{'en': 'Date', 'de': 'Datum', 'fr': 'Date', 'it': 'Data'}],
      'y1AxisLabel': [{'en': 'Power (GW)',
        'de': 'Leistung (GW)',
        'fr': 'Puissance (GW)',
        'it': 'Prestazione (GW)'}],
      'y1AxisDecimalPlaces': 2,
      'y2AxisLabel': [{'en': 'Price (Euro\u200a/\u200aMWh, Euro\u200a/\u200at\u200aCO2)',
        'de': 'Preis (Euro\u200a/\u200aMWh, Euro\u200a/\u200at\u200aCO2)',
        'fr': 'Prix (Euro\u200a/\u200aMWh, Euro\u200a/\u200at\u200aCO2)',
        'it': 'Prestazione (Euro\u200a/\u200aMWh, Euro\u200a/\u200at\u200aCO2)'}],
      'y2AxisDecimalPlaces': 2,
      'datasource': 'EPEX SPOT, 50 Hertz, Amprion, Tennet, TransnetBW',
      'date': 1588597666000,
      'type': 'area',
      'yAxis': '1',
      'values': [[1546297200000, -10.903],
       [1546300800000, -10.997],
       [1546304400000, -11.824],
       [1546308000000, -11.964],
       [1546311600000, -12.62],
       [1546315200000, -13.395],
       [1546318800000, -13.692],
       [1546322400000, -14.037],
       [1549882800000, -9.639],
       [1549886400000, -8.662],
       [1549890000000, -8.091],
       [1549893600000, -8.378],
       ...]},
     {'key': [{'en': 'Conventional > 100 MW',
        'de': 'Konventionell > 100 MW',
        'fr': 'Conventionnel > 100 MW',
        'it': 'Convenzionale > 100 MW'}],
      'color': 'rgb(158,152,148)',
      'type': 'area',
      'yAxis': '1',
      'values': [[1546297200000, 21.848],
       [1546300800000, 19.218],
       [1546304400000, 18.027],
       [1546308000000, 17.161],
       [1546311600000, 16.942],
       [1546315200000, 16.703],
       [1546318800000, 16.569],
       [1546322400000, 16.709],
6
  • 1
    write something like EnergyData["key"]["en"]["Import Balance"][0] - EnergyData[0]["key"][0]["en"] would result in "Import Balance". The first number (1546297200000) stored in the list of values would be EnergyData[0]["values"][0][0]. Just navigate it like you would with addresses consisting of country, state, zip code, street name, house number, appartment number. Use strings (in this case) for dictionaries and integers for lists. Commented Jan 4, 2022 at 22:00
  • 1
    I don't think that's correct - the first number (1546297200000) is located at EnergyData[0]['values'][0][0], no? Commented Jan 4, 2022 at 22:01
  • 1
    But how do I type this - I'm not sure what you mean by that ... with a keyboard? It's a list, with dict elements and then a list with data? - yes ...? Commented Jan 4, 2022 at 22:06
  • mkrieger1's comments result in the output that he says. But I had expected that the data could be accessed in a more readable way - but perhaps this isn't the case then. The source seem to use the multiple dict objects to display language dependent text in a graph. Commented Jan 5, 2022 at 14:01
  • EnergyData[1]["values"][0][:2] yields [1546297200000, 21.848] Ideally, I would have liked to address the data with the "key" "Conventional > 100 MW" Commented Jan 5, 2022 at 14:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.