Get data from python datastream api

import DatastreamPy as dsws
ds=dsws.Datastream(username='****',password='****')

d = ds.get_data (tickers='BARC', fields=['P'], start='2018-01-01', end='2023-03-01', freq='W')

How can I retrieve price data from "d". I intend to store it in database but am not able to access data.

d returns None

Best Answer

  • Gurpreet
    Answer ✓

    I tried the query and the dataframe d is not None.

    >>> d = ds.get_data (tickers='BARC', fields=['P'], start='2018-01-01', end='2023-03-01', freq='W')
    >>> d
    Instrument BARC
    Field P
    Currency £
    Dates
    2018-01-01 203.13
    2018-01-08 200.10
    ... ...
    2023-02-20 175.88
    2023-02-27 172.64

    [270 rows x 1 columns]

    >>> d.info()
    <class 'pandas.core.frame.DataFrame'>
    Index: 270 entries, 2018-01-01 to 2023-02-27
    Data columns (total 1 columns):
    # Column Non-Null Count Dtype
    --- ------ -------------- -----
    0 (BARC, P, £) 270 non-null float64
    dtypes: float64(1)

    You can get the series data from it by accessing it like this -

    >>> d['BARC', 'P', '£']
    Dates
    2018-01-01 203.13
    2018-01-08 200.10
    ...
    2023-02-20 175.88
    2023-02-27 172.64
    Name: (BARC, P, £), Length: 270, dtype: float64


Answers