Explore
Groups
No topics yet. Start the conversation.
Summary
User supplied summary for the plot
The largest detractors to the Energy sector may 2023 performance.
Description
The below description is supplied in free-text by the user
Novem Example Index top and bottom performers
This table is an example of how you can highlight top and bottom performers for a fictive equity index or portfolio. The code with comments is available below. Curious about the data side? Check out how we created the sample data. Want to learn more about novem and pandas? We have an article for that.
import pandas as pd
from novem import Plot
from novem.colors import StaticColor as SC, DynamicColor as DC
from novem.table import Selector as S
# grab our example numbers from novem data
df = pd.read_csv('nei_sector_energy_bot.csv', index_col=0)
# let's convert our Contribution to bps, Basis points)
# Create a novem e-mail table `mtable`
tb = Plot('nei_sector_energy_bot_may', type='table', config_path='test.conf')
# add our data
df.pipe(tb)
# right align our nmbers
tb.cell.align = """
: : <
: -5: >
"""
# add some spacing to the left and right of numbers
tb.cell.padding = """
: :-2 r 3
"""
# let's format our numbers, first set NAV and all following
# numbers as decimal, then override Return as percent
tb.cell.format = """
: : ,.2f
1: -4: ,.2%
"""
# use index colors
tb.colors.type = 'ix'
tb.colors = S(df.loc[df.index.isin(['EQNR']) , :], SC("bg", "red-100"), df, c=":")
tb.colors += """
1: -1 fg red-600,red-300(_,0)^lin
1: -2 fg red-600,red-300(_,0)^lin
1: -3 fg red-600,red-300(_,0)^lin
"""
# finaly let's bold the text and add a bottom border to the top row, we'll add
# this manually as pandas slicing doens't make it easy to slice for the index
# row
tb.cell.border = '0 : b 1 inverse' # row 0, all columns, bottom 1 wide border
# with the "inverse" color
tb.cell.text = '0 : b' # row 0, all columns, bold text
# add a caption to the table
tb.caption = """Top detractors to the energy sector in may. Weight is weight within the energy sector and
contribution is contribution to the sectors performance. Nav in million USD, MTD and YTD is
the individual security performance for May and YTD in 2023."""
# Let's add a discriptive name
tb.name = "Novem Example Index - Largest detractors in the Energy sector in May"
# and a short summary
tb.summary = "The largest detractors to the Energy sector may 2023 performance."
# share it with the world
tb.shared += 'public'
tb.shared += 'chat'
# let's print our url
print(tb.url) # https://novem.no/p/NJy4w
tb.type = 'mtable'
with open(__file__,'r') as f:
ctnt = f.read().replace('```','```') # turtles
desc = f"""
# Novem Example Index top and bottom performers
This table is an example of how you can highlight top and bottom performers
for a fictive equity index or portfolio. The code with comments is available below.
Curious about the data side? [Check out how we created the sample data.](https://novem.no/blog/creating-the-novem-example-index/)
Want to learn more about novem and pandas? [We have an article for that.](https://novem.no/blog/novem-pandas/)
```
{ctnt}
```
"""
tb.description = desc