0

I downloaded a file with extension .A which contains a time series I would like to work on in Python. I'm not an expert at all with .A files, but if I open it with a notepad I see it contains the data I'd like to work on. How can I conver that file in Python in order to work on it (i.e. an array, a pandas series...)?

import requests
response = requests.get("https://sdw-wsrest.ecb.europa.eu/service/data/EXR/D.USD.EUR.SP00.A?startPeriod=2021-02-20&endPeriod=2021-02-25")
data = response.text
martineau
  • 119,623
  • 25
  • 170
  • 301
unter_983
  • 167
  • 6

1 Answers1

1

You need to read up on parsing XML. This code will get the data into a data structure typical for XML. You may mangle it as you see fit from there. You need to provide more information about how you'd like these data to look in order to get a more complete answer.

import requests
import xml.etree.ElementTree as ET


response = requests.get("https://sdw-wsrest.ecb.europa.eu/service/data/EXR/D.USD.EUR.SP00.A?startPeriod=2021-02-20&endPeriod=2021-02-25")
data = response.text
root = ET.fromstring(data)
Michael Ruth
  • 2,938
  • 1
  • 20
  • 27
  • Unfortunately I have no experience with XML. Let's say I'd like to have a pandas dataframe. Is there a direct way to convert that ET object? – unter_983 Mar 06 '21 at 09:20
  • 1
    Check this answer out, it may help you start: https://stackoverflow.com/questions/28259301/how-to-convert-an-xml-file-to-nice-pandas-dataframe The issue here is that XML isn't a flat datatype and `pandas.DataFrame` is, so there's no single mapping from XML to `pandas.DataFrame`. You'll need to define what you'd like your data to look like. – Michael Ruth Mar 06 '21 at 09:27