LSEG Data Library for Python

Pandas configuration

The LSEG Data Library for Python uses Pandas to build DataFrames.
Pandas has an options API that configures and customises the global behaviour of DataFrame display, data behaviour, and more.

You are able to configure and customize it as well.

For example, the standard floating point output precision is for six digits after the decimal. For example:

import os

import lseg.data as ld

APP_KEY = os.environ.get("DESKTOP_APP_KEY")

session = ld.session.desktop.Definition(app_key=APP_KEY).get_session()
ld.session.set_default(session)
session.open()

df = ld.get_data(
    "MSFT.O",
    [
        'RSI(TR.Close(sdate=0d,edate=-9d,frq=d))',
        'TR.CommonName', 'CF_CLOSE'
    ]
)
print(df.to_string())
session.close()

This example produces the following output:

  Instrument  RSI(TR.Close(sdate=0d,edate=-9d,frq=d)) Company Common Name  CF_CLOSE
0     MSFT.O                                56.938519      Microsoft Corp    295.37

You can change the number of digits after the decimal to 10 digits, for example, in the following manner:

import os

import pandas as pd

import lseg.data as ld

APP_KEY = os.environ.get("DESKTOP_APP_KEY")
pd.options.display.precision = 10

session = ld.session.desktop.Definition(app_key=APP_KEY).get_session()
ld.session.set_default(session)
session.open()

df = ld.get_data(
    "MSFT.O",
    [
        'RSI(TR.Close(sdate=0d,edate=-9d,frq=d))',
        'TR.CommonName', 'CF_CLOSE'
    ]
)
print(df.to_string())

session.close()

This example produces the following output:

  Instrument  RSI(TR.Close(sdate=0d,edate=-9d,frq=d)) Company Common Name  CF_CLOSE
0     MSFT.O                            56.9385194479      Microsoft Corp    295.37

You can find further information about this in the Pandas options and settings chapter of Pandas documentation.

99 words (0:31 mins)