python - How to remove 1 of 2 decimal points in a number using Pandas -


i have column of numbers in excel ... e.g.

1.2345.678  

i want remove second decimal point data.

is possible via import csv dataframe?

thanks.

the following preserve digits , rid of final decimal point wanted:

in [80]: t="""val 1.2345.678""" df = pd.read_csv(io.stringio(t)) df  out[80]:           val 0  1.2345.678  in [94]:     (df['val'].str[0:df['val'].str.rfind('.')[0]]+df['val'].str.split('.').str[-1]).astype(np.float64)  out[94]: 0    1.234568 dtype: float64 

note above shows display truncation, full value present

so above slices string beginning position of last decimal point, split string , add last split, can convert float using astype

edit

a better way think second part not split rather re-use rfind positioning:

in [113]: df['val'].str[0:df['val'].str.rfind('.')[0]]+df['val'].str[df['val'].str.rfind('.')[0]+1:]  out[113]: 0    1.2345678 name: val, dtype: object 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -