Guest User

Untitled

a guest
Mar 18th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. import pandas as pd
  2. from IPython.display import display, HTML
  3.  
  4. def format_dollar(x):
  5. return "${:,.0f}".format(x)
  6.  
  7. df = pd.DataFrame({'Region': ['West', 'West', 'South', 'South', 'South', 'South'],
  8. 'Product': ['A', 'B', 'A', 'B', 'A', 'A'],
  9. 'Value': [10000, 200, 15, 13, 100, 100],
  10. 'Value2': [11, 13, 1200, 100, 30, 10]})
  11. df = df.pivot_table(values=['Value', 'Value2'],
  12. index=['Product', 'Region'])
  13. df['Value'] = df['Value'].apply(format_dollar)
  14.  
  15. display(df)
Add Comment
Please, Sign In to add comment