Skip to content

column datatype conversion impacts whole dataframe when using df.ix indexing #8607

Closed
@dmarx

Description

@dmarx

My dataframe has a timestamp column that is encoded as unix epoch. When I convert the column using named index selection it works fine, but when I use the '.ix' syntax it coerces the whole dataframe. Example:

import pandas as pd

df = pd.DataFrame(
    {'timestamp':[1413840976, 1413842580, 1413760580], 
     'delta':[1174, 904, 161], 
     'elapsed':[7673, 9277, 1470]
    })

df2 = df.copy()

df['timestamp'] = pd.to_datetime(df['timestamp'], unit='s')
df2.ix[:,2] = pd.to_datetime(df['timestamp'], unit='s')

df

    delta    elapsed    timestamp
0    1174    7673    2014-10-20 21:36:16
1    904    9277    2014-10-20 22:03:00
2    161    1470    2014-10-19 23:16:20

df2

    delta    elapsed    timestamp
0    2014-10-20 21:36:16    1970-01-01 00:00:00.000007673    1970-01-01 00:00:01.413840976
1    2014-10-20 22:03:00    1970-01-01 00:00:00.000009277    1970-01-01 00:00:01.413842580
2    2014-10-19 23:16:20    1970-01-01 00:00:00.000001470    1970-01-01 00:00:01.413760580

I strongly suspect the difference in behavior here is problematic and should be resolved. If this is actually "how things should work," I'd greatly appreciate it if someone could explain why the different indexing styles produce these different results

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions