User Tools

Site Tools


add_commas

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
add_commas [2021/01/13 20:47] – [add commas] rajuadd_commas [2021/01/13 20:53] – [input is a single number; without pandas] raju
Line 3: Line 3:
 search tags | f strings, thousands separator, format integers with commas search tags | f strings, thousands separator, format integers with commas
 ==== input is a single number; without pandas ==== ==== input is a single number; without pandas ====
 +  * '{:,}'.format(value)  # For Python ≥2.7
 +  * f'{value:,}'  # For Python ≥3.6
 +
 <code> <code>
 In [1]: In [1]:
Line 22: Line 25:
 </code> </code>
  
-Ref:- https://mail.python.org/pipermail/python-list/2020-May/896878.html+Examples using a print statement 
 +<code> 
 +In [1]: 
 +a = 123456 
 + 
 +In [2]: 
 +print('The magic number is = {alpha:,}'.format(alpha=a)) 
 +The magic number is = 123,456 
 + 
 +In [3]: 
 +print('The magic number is = {:,}'.format(a)) 
 +The magic number is = 123,456 
 + 
 +In [4]: 
 +print('The magic number is = {:}'.format(a)) 
 +The magic number is = 123456 
 +</code> 
 + 
 +Ref:- 
 +  * https://stackoverflow.com/questions/1823058/how-to-print-number-with-commas-as-thousands-separators 
 +  * https://mail.python.org/pipermail/python-list/2020-May/896878.html
  
 ==== input is a dataframe ==== ==== input is a dataframe ====
add_commas.txt · Last modified: 2021/01/13 20:57 by raju