Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3.  
  4. # In[27]:
  5.  
  6.  
  7. import pandas as pd
  8.  
  9. GDP_2017 = 19519400000000
  10. GDP_2016 = 18707200000000
  11. ratio = GDP_2017/GDP_2016 - 1
  12.  
  13. df_int = pd.DataFrame(
  14. [{'Number': GDP_2017, 'Format': '{:,}', 'Purpose': 'Thousand separator'},
  15. {'Number': GDP_2016, 'Format': '{:.2e}', 'Purpose': 'Scientific format with exponent notation'},
  16. {'Number': GDP_2017, 'Format': '{:,.2f}', 'Purpose': 'Thousand separator with fixed decimal places'},
  17. {'Number': GDP_2016, 'Format': '{:>30}', 'Purpose': 'Thousand separator with fixed decimal places'}
  18. ],
  19.  
  20. columns = ['Purpose', 'Number', 'Format'])
  21.  
  22. df_float = pd.DataFrame([{'Number': ratio, 'Format': '{:.2%}', 'Purpose': 'Percentage'},
  23. {'Number': ratio, 'Format': '{:.2e}', 'Purpose': 'Scientific format with exponent notation'}],
  24. columns = ['Purpose', 'Number', 'Format'])
  25. display(df_int.head())
  26. df_float.head()
  27.  
  28.  
  29. # In[28]:
  30.  
  31.  
  32. df_int['Output'] = df_int.apply(lambda x: str(x[2]).format(x[1]), axis=1)
  33. print(df_int.head())
  34. df_int.to_csv('df_int.csv')
  35.  
  36.  
  37. # In[10]:
  38.  
  39.  
  40. df_float['Output'] = df_float.apply(lambda x: str(x[2]).format(x[1]), axis=1)
  41. df_float.head()
  42. # df_float.to_csv('df_float.csv')
  43.  
  44.  
  45. # In[ ]:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement