Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- from IPython.display import display, HTML
- def format_dollar(x):
- return "${:,.0f}".format(x)
- df = pd.DataFrame({'Region': ['West', 'West', 'South', 'South', 'South', 'South'],
- 'Product': ['A', 'B', 'A', 'B', 'A', 'A'],
- 'Value': [10000, 200, 15, 13, 100, 100],
- 'Value2': [11, 13, 1200, 100, 30, 10]})
- df = df.pivot_table(values=['Value', 'Value2'],
- index=['Product', 'Region'])
- df['Value'] = df['Value'].apply(format_dollar)
- display(df)
Add Comment
Please, Sign In to add comment