[Python] A basic example of IMFs sdmx in Python

Discussão em 'Python' iniciado por Stack, Maio 3, 2025.

  1. Stack

    Stack Membro Participativo

    I am using Positron with Python 3.13.3 version. Now, my first attempt in Python coding is to replicate IMF's standard code from this page and it is:

    # import libraries
    import sdmx

    # retrieve data
    IMF_DATA = sdmx.Client('IMF_DATA')
    data_msg = IMF_DATA.data('CPI', key='USA+CAN.CPI.CP01.IX.M', params={'startPeriod': 2018})

    # convert to pandas
    cpi_df = sdmx.to_pandas(data_msg)

    print(cpi_df.head())


    I successfully installed the sdmx library before. However, when I ran the code line by line, I got the following error (below): What is wrong with my replication? Thanks!

    >>> %run "c:\\Test_IMF.py"
    NameError: name 'IMF_DATA' is not defined
    File C:\R\NRT\Test_IMF.py:5
    2 import sdmx
    4 # retrieve data
    ----> 5 data_msg = IMF_DATA.data('CPI', key='USA+CAN.CPI.CP01.IX.M', params={'startPeriod': 2018})
    7 # convert to pandas
    8 cpi_df = data_msg.to_pandas()

    Continue reading...

Compartilhe esta Página