0

I have string and digits in my dataframe which look like this

  number 
1.52E+11
8.12E+11
FAY853
GUGY

my expected result will be look like this

    number
  152000000000
  812000000000  
  FAY853
  GUGY

I want to show full digits. How to handle number and digits together ? and show only full digits for large number.

I tried pd.set_option('display.float_format', '{:.2f}'.format) but didn't work. Showing the same result like original dataframe

boyenec
  • 1,405
  • 5
  • 29
  • Does this work? `pd.options.display.float_format = '{:20,.2f}'.format` –  May 03 '22 at 23:26
  • no didn't work `pd.options.display.float_format = '{:20,.2f}'.format` – boyenec May 03 '22 at 23:29
  • Hmm...take a look at the questions I linked above, and then tell me if they help or not, and I'll reopen this question. Possibly you need to do `df['number'] = df['number'].astype(float)` first... –  May 03 '22 at 23:30
  • richardec I also have string data in my number column so this solution will not work for this situation. – boyenec May 03 '22 at 23:33

1 Answers1

0

This is a bit clumsy I reckon, but this worked as ._convert(numeric=True) will output NaN in case it encounters strings

import numpy as np
df['new']=df['number']._convert(numeric=True)
df['new']=df.apply(lambda row:format(row['new'],'.0f'),axis=1)
df['number']=np.where(df['new']=='nan',df['number'],df['new'])
df.drop('new',axis=1,inplace=True)

df
Daniel Weigel
  • 1,097
  • 2
  • 8
  • 14