Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # coding: utf-8
- # In[27]:
- import pandas as pd
- GDP_2017 = 19519400000000
- GDP_2016 = 18707200000000
- ratio = GDP_2017/GDP_2016 - 1
- df_int = pd.DataFrame(
- [{'Number': GDP_2017, 'Format': '{:,}', 'Purpose': 'Thousand separator'},
- {'Number': GDP_2016, 'Format': '{:.2e}', 'Purpose': 'Scientific format with exponent notation'},
- {'Number': GDP_2017, 'Format': '{:,.2f}', 'Purpose': 'Thousand separator with fixed decimal places'},
- {'Number': GDP_2016, 'Format': '{:>30}', 'Purpose': 'Thousand separator with fixed decimal places'}
- ],
- columns = ['Purpose', 'Number', 'Format'])
- df_float = pd.DataFrame([{'Number': ratio, 'Format': '{:.2%}', 'Purpose': 'Percentage'},
- {'Number': ratio, 'Format': '{:.2e}', 'Purpose': 'Scientific format with exponent notation'}],
- columns = ['Purpose', 'Number', 'Format'])
- display(df_int.head())
- df_float.head()
- # In[28]:
- df_int['Output'] = df_int.apply(lambda x: str(x[2]).format(x[1]), axis=1)
- print(df_int.head())
- df_int.to_csv('df_int.csv')
- # In[10]:
- df_float['Output'] = df_float.apply(lambda x: str(x[2]).format(x[1]), axis=1)
- df_float.head()
- # df_float.to_csv('df_float.csv')
- # In[ ]:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement