{"action":"created","issue":{"url":"https://api.github.com/repos/pandas-dev/pandas/issues/20511","repository_url":"https://api.github.com/repos/pandas-dev/pandas","labels_url":"https://api.github.com/repos/pandas-dev/pandas/issues/20511/labels{/name}","comments_url":"https://api.github.com/repos/pandas-dev/pandas/issues/20511/comments","events_url":"https://api.github.com/repos/pandas-dev/pandas/issues/20511/events","html_url":"https://github.com/pandas-dev/pandas/issues/20511","id":309239436,"number":20511,"title":"Assign back converted multiple columns to datetime failed","user":{"login":"jesrael","id":10682573,"avatar_url":"https://avatars2.githubusercontent.com/u/10682573?v=4","gravatar_id":"","url":"https://api.github.com/users/jesrael","html_url":"https://github.com/jesrael","followers_url":"https://api.github.com/users/jesrael/followers","following_url":"https://api.github.com/users/jesrael/following{/other_user}","gists_url":"https://api.github.com/users/jesrael/gists{/gist_id}","starred_url":"https://api.github.com/users/jesrael/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jesrael/subscriptions","organizations_url":"https://api.github.com/users/jesrael/orgs","repos_url":"https://api.github.com/users/jesrael/repos","events_url":"https://api.github.com/users/jesrael/events{/privacy}","received_events_url":"https://api.github.com/users/jesrael/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-28T06:42:09Z","updated_at":"2018-03-28T19:55:10Z","closed_at":"2018-03-28T19:55:10Z","author_association":"NONE","body":"I want convert multiple columns to datetimes:\r\n\r\n    df = pd.DataFrame(np.random.choice(['2015-01-01','2016-01-01'], size=(5,6))).add_prefix('date')\r\n    print (df)\r\n            date0       date1       date2       date3       date4       date5\r\n    0  2015-01-01  2016-01-01  2015-01-01  2015-01-01  2016-01-01  2016-01-01\r\n    1  2016-01-01  2016-01-01  2016-01-01  2015-01-01  2016-01-01  2015-01-01\r\n    2  2015-01-01  2015-01-01  2016-01-01  2016-01-01  2016-01-01  2015-01-01\r\n    3  2016-01-01  2015-01-01  2015-01-01  2015-01-01  2015-01-01  2015-01-01\r\n    4  2015-01-01  2016-01-01  2015-01-01  2016-01-01  2016-01-01  2015-01-01\r\n    \r\n    i= range(0,6,2)\r\n    df.iloc[:,i] = df.iloc[:,i].apply(lambda x: pd.to_datetime(x, errors='coerce'))\r\n    print (df.dtypes)\r\n    date0    object\r\n    date1    object\r\n    date2    object\r\n    date3    object\r\n    date4    object\r\n    date5    object\r\n    dtype: object\r\n    \r\n    print (df)\r\n                     date0       date1                date2       date3  \\\r\n    0  1420070400000000000  2016-01-01  1420070400000000000  2015-01-01   \r\n    1  1451606400000000000  2016-01-01  1451606400000000000  2015-01-01   \r\n    2  1420070400000000000  2015-01-01  1451606400000000000  2016-01-01   \r\n    3  1451606400000000000  2015-01-01  1420070400000000000  2015-01-01   \r\n    4  1420070400000000000  2016-01-01  1420070400000000000  2016-01-01   \r\n    \r\n                     date4       date5  \r\n    0  1451606400000000000  2016-01-01  \r\n    1  1451606400000000000  2015-01-01  \r\n    2  1451606400000000000  2015-01-01  \r\n    3  1420070400000000000  2015-01-01  \r\n    4  1451606400000000000  2015-01-01  \r\n\r\nI test converting:\r\n\r\n    print (df.iloc[:,i].apply(lambda x: pd.to_datetime(x, errors='coerce')).dtypes)\r\n    date0    datetime64[ns]\r\n    date2    datetime64[ns]\r\n    date4    datetime64[ns]\r\n    dtype: object\r\n\r\nBut assign back convert datetimes to unix dates. Also I test `loc` and same problem.\r\n\r\n    print (pd.show_versions())\r\n    \r\n    INSTALLED VERSIONS\r\n    ------------------\r\n    commit: None\r\n    python: 3.5.1.final.0\r\n    python-bits: 64\r\n    OS: Windows\r\n    OS-release: 7\r\n    machine: AMD64\r\n    processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel\r\n    byteorder: little\r\n    LC_ALL: None\r\n    LANG: sk_SK\r\n    LOCALE: None.None\r\n    \r\n    pandas: 0.22.0\r\n    pytest: 2.8.5\r\n    pip: 9.0.1\r\n    setuptools: 38.4.0\r\n    Cython: 0.23.4\r\n    numpy: 1.12.1\r\n    scipy: 0.19.0\r\n    pyarrow: 0.7.0\r\n    xarray: None\r\n    IPython: 4.1.2\r\n    sphinx: 1.3.1\r\n    patsy: 0.4.1\r\n    dateutil: 2.5.1\r\n    pytz: 2016.2\r\n    blosc: None\r\n    bottleneck: 1.2.1\r\n    tables: 3.2.2\r\n    numexpr: 2.6.2\r\n    feather: 0.4.0\r\n    matplotlib: 2.0.0\r\n    openpyxl: 2.4.8\r\n    xlrd: 0.9.4\r\n    xlwt: 1.0.0\r\n    xlsxwriter: 0.8.4\r\n    lxml: 3.6.0\r\n    bs4: 4.6.0\r\n    html5lib: 0.999\r\n    sqlalchemy: 1.0.12\r\n    pymysql: None\r\n    psycopg2: None\r\n    jinja2: 2.8\r\n    s3fs: None\r\n    fastparquet: None\r\n    pandas_gbq: None\r\n    pandas_datareader: 0.4.0\r\n    None\r\n"},"comment":{"url":"https://api.github.com/repos/pandas-dev/pandas/issues/comments/377015122","html_url":"https://github.com/pandas-dev/pandas/issues/20511#issuecomment-377015122","issue_url":"https://api.github.com/repos/pandas-dev/pandas/issues/20511","id":377015122,"user":{"login":"TomAugspurger","id":1312546,"avatar_url":"https://avatars3.githubusercontent.com/u/1312546?v=4","gravatar_id":"","url":"https://api.github.com/users/TomAugspurger","html_url":"https://github.com/TomAugspurger","followers_url":"https://api.github.com/users/TomAugspurger/followers","following_url":"https://api.github.com/users/TomAugspurger/following{/other_user}","gists_url":"https://api.github.com/users/TomAugspurger/gists{/gist_id}","starred_url":"https://api.github.com/users/TomAugspurger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomAugspurger/subscriptions","organizations_url":"https://api.github.com/users/TomAugspurger/orgs","repos_url":"https://api.github.com/users/TomAugspurger/repos","events_url":"https://api.github.com/users/TomAugspurger/events{/privacy}","received_events_url":"https://api.github.com/users/TomAugspurger/received_events","type":"User","site_admin":false},"created_at":"2018-03-28T19:55:10Z","updated_at":"2018-03-28T19:55:10Z","author_association":"CONTRIBUTOR","body":"It's not entirely clear what you're trying to do. For\r\n\r\n> I want convert multiple columns to datetimes:\r\n\r\nyou can use `apply` and `to_datetime`\r\n\r\n```python\r\nIn [15]: df2 = df.apply(pd.to_datetime, errors='coerce')\r\n\r\nIn [16]: df2.dtypes\r\nOut[16]:\r\ndate0    datetime64[ns]\r\ndate1    datetime64[ns]\r\ndate2    datetime64[ns]\r\ndate3    datetime64[ns]\r\ndate4    datetime64[ns]\r\ndate5    datetime64[ns]\r\ndtype: object\r\n```"}}
{"actor":{"display_login":"TomAugspurger"}}