Pandas DataFrame.replace function violated for date and time

In pandas v0.17.1 (anaconda python v3.4.3) the replace function is datetimebroken.

I am trying to replace the string value in mine DataFramewith a new value. This one DataFramecontains several columns (including a data column). Replace
function doesn't work

>>> from datetime import datetime
>>> import pandas as pd
>>> df = pd.DataFrame({'no':range(4), 'nm':list('abcd'), 'tm':datetime.now()})
>>> df.replace('a', 'A')

Traceback (last last call): File "/home/xxx/anaconda/envs/py3/lib/python3.4/site-packages/ pandas / core / internals.py", line 2061, in _try_coerce_args other = other.astype ( 'i8', copy = False) .view ('i8') ValueError: invalid literal for int () with base 10: 'a'

When processing the above exception, another exception occurred:

Traceback (last last call): File "/home/xxx/anaconda/envs/py3/lib/python3.4/site-packages/ pandas / core / internals.py", line 594, replace values, _, to_replace, _ = self._try_coerce_args (self.values, to_replace) File "/home/xxx/anaconda/envs/py3/lib/python3.4/site-packages/pandas/core/internals.py", line 2066, in _try_coerce_args raise TypeError TypeError

When processing the above exception, another exception occurred:

Traceback ( ): ", 1,    " /home/xxx/anaconda/envs/py 3/lib/python3.4/site-packages/ pandas/core/generic.py", 3110,     inplace = inplace, regex = regex) "/home/xxx/anaconda/envs/py3/lib/python3.4/site-packages/pandas/core/internals.py" , 2870,     return self.apply("replace", ** kwargs) "/home/xxx/anaconda/envs/py3/lib/python3.4/site-packages/pandas/core/internals.py" , 2823,     apply = getattr (b, f) (** kwargs) "/home/xxx/anaconda/envs/py3/lib/python3.4/site-packages/pandas/core/internals.py" , 607,     if not mask.any(): UnboundLocalError: 'mask',

pandas 0.16.2.
?

+4
1

, master 0.18 ( 2016 ): https://github.com/pydata/pandas/issues/11868 0.17.1.


( , ), - 0.17.1:

for c in df.select_dtypes(include=["object"]).columns:
    df[c] = df[c].replace('a', 'A')
+2

Source: https://habr.com/ru/post/1620856/


All Articles