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