Question: When I use iloc to set a datetime value to a dataframe cell, the value is changed

```
import datetime as dt
import pandas as pd

t = '2019-12-29 13:17:34.678000'
t = dt.datetime.fromisoformat(t)
print(t)
# 2019-12-29 13:17:34.678000

df = pd.DataFrame({'t': [t]})
print(df)
#                         t
# 0 2019-12-29 13:17:34.678

df.iloc[0, df.columns.get_loc('t')] = t
print(df)
#                               t
# 0 2019-12-29 13:17:34.678000128

```

Why is this happening and how can I prevent it?

Answer: 
You can apply function `isoformat` that will trunc time to milliseconds removing microsecond precision:

```
t = dt.datetime.fromisoformat(t).isoformat(timespec='milliseconds')

```

For details regarding isoformat, please follow: <https://docs.python.org/3/library/datetime.html#datetime.time.microsecond> 

Please note that as documentation says, excluded time components are truncated, not rounded.
This seems to be a bug in pandas `0.25.2`. It doesn't happen in the latest version, `1.0.1`.

In `0.25.2` it can be worked around by using `.at` instead of `.iloc`

```
t = '2019-12-29 13:17:34.678000'
t = dt.datetime.fromisoformat(t)
print(t)
# 2019-12-29 13:17:34.678000

df = pd.DataFrame({'t': [t]})
print(df)
#                         t
# 0 2019-12-29 13:17:34.678

df.at[0, 't'] = t
print(df)
#                         t
# 0 2019-12-29 13:17:34.678

```