0

Desire format:

CODE: "0700.1707300","2700.1707380","0060.1500000","3400.1600215"

Dataset:

dt = pd.DataFrame({"CODE": 
["700.17073","2700.170738","60.150","3400.1600215"}) # dtype('float64')

Example:

IN: '{:012.7f}'.format(700.17073) 
OUT: '0700.1707300' <-- return desire format

Problem: CODE.rjust,CODE.ljust convert only one part before / after decimal of the index. OR Getting error by this script :

dt["CODE"].loc[dt["CODE"].'{:012.7f}'.format()] 

In R data.table:

dt[,CODE:=formatC(as.numeric(CODE), format = 'f', width = 12, flag = '0', digits = 7)] <-- can achieve by formatC

How to update this column from dtype('float64') into desire formatting?

Georgy
  • 12,464
  • 7
  • 65
  • 73
rane
  • 901
  • 4
  • 12
  • 24
  • Possible duplicate of [How to display pandas DataFrame of floats using a format string for columns?](https://stackoverflow.com/questions/20937538/how-to-display-pandas-dataframe-of-floats-using-a-format-string-for-columns) – Georgy Jul 26 '19 at 10:32
  • Georgy thanks for sharing the link but its not changing the index , just displaying in different format ?(`print df.to_string(formatters={'cost':'${:,.2f}'.format}) `) also , where is the answer from the question tells how to add fixed value (like: 0) before decimal ? – rane Jul 27 '19 at 17:00

1 Answers1

0

Solved :

df['CODE'] = df['CODE'].map('{:012.7f}'.format)
rane
  • 901
  • 4
  • 12
  • 24