trim nanoseconds to 100's of a nanosecond in python (pandas) -


i have datetime in nanosecond format in pandas dataframe (full):

2017-06-30 08:53:58.940891100  2017-06-30 08:53:58.940891200 

to get:

2017-06-30 08:53:58.9408911  2017-06-30 08:53:58.9408912 

i want trim of last 2 digits can keep datetime in ticks use in .net datetime object later:

at moment have tried this:

full['datetime'].dt.strftime('%y-%m-%d %h:%m:%s.%f0') 

but limits microseconds additional 0 , need hundredth of nanosecond precision.

any ideas?

if want trim us use floor , remove last 2 0 , convert strings use astype str[:-2]:

full['datetime2'] = full['datetime'].dt.floor('u') full['datetime3'] = full['datetime'].astype(str).str[:-2] print (full)                        datetime                  datetime2  \ 0 2017-06-30 08:53:58.940891100 2017-06-30 08:53:58.940891    1 2017-06-30 08:53:58.940891200 2017-06-30 08:53:58.940891                          datetime3   0  2017-06-30 08:53:58.9408911   1  2017-06-30 08:53:58.9408912    print (type(full.loc[0, 'datetime2'])) <class 'pandas._libs.tslib.timestamp'>  print (type(full.loc[0, 'datetime3'])) <class 'str'> 

Comments

Popular posts from this blog

Add new key value to json node in java -

javascript - Highcharts Synchronized charts with missing data points -

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -