Option added to the API to output results to a Pandas dataframe

We have added a parameter the to data, data_universe and rank_ranks API endpoints which will output the results to a Pandas DataFrame. A Pandas DataFrame is a 2 dimensional data structure, like a table with rows and columns. The example below shows how this parameter is used in the data_universe endpoint. ‘True’ will output the data to a DataFrame.

import p123api
import pandas as pd

try:
    client = p123api.Client(api_id='<your id>', api_key='<you api key here>')

    df = client.data_universe(
        {
            "universe": "DJIA",
            "asOfDt": "2019-11-06",
            'formulas': [
                'FRank("PEExclXorTTM",#All,#ASC)',
                'FRank("ROI%TTM",#All,#DESC)',
                'FRank("OpMgn%TTM",#All,#DESC)',
                'Rel%Chg(253,#Sector)'
            ]
        }, True)  #True to output to dataframe

    #Rename the column headers if needed.
    df2 = df.rename({'formula1': 'PE', 'formula2': 'ROI', 'formula3': 'OpMgn', 'formula4': 'Rel%ChgVsSector'}, axis='columns')

    pd.set_option('display.max_rows', None)
    pd.set_option('display.max_columns', None)
    pd.set_option('display.width', None)
    #pd.set_option('display.max_colwidth', 20)
    print(df2)

except p123api.ClientException as e:
    print(e)

The first few lines of output from the example above will look like this:

p123Uids tickers      PE     ROI   OpMgn  Rel%ChgVsSector
0        592     AXP   80.00   30.00   50.00             4.22
1      62197     DOW   20.00   10.00   20.00              NaN
2       9150     RTX   36.67   20.00   33.33             5.07
3       5881    MSFT   23.33   83.33   86.67            13.33

awesome… thanks guys

Thanks!

The documentation says DataMiner can be downloaded on a Mac.

Is this the DataMiner_linux.tar.gz file?

Looks awesome even if I have not tried it yet!!! And good explanation too.

Jim

Hi Jim. Sorry but the Mac install package for DataMiner is not ready yet. We will make an announcement in this forum when it is ready.

I’m not able to run this code. I’ve probably messed something up, but I notice that the P123 API I’m using (latest version from Github) is 4 months old - how do I access the latest version?

You can update your p123api package to the latest version by running the following at a command prompt: pip install -U p123api

You will also need to install Pandas if you do not have it. To install Pandas, run this at a command prompt: pip install pandas

If you are still getting an error, please post the error message.

This solved my problem - Thanks!