Skip to content

API: arithmetic ops could accept an index as appropriate #4629

@jreback

Description

@jreback

Not sure if this will cause weirdness but haveing the arithmetic operations able to accept an index (when appropriate type), e.g. a datecolumn should be able to interact with a DatetimeIndex, but prob should prohibit an int column from interacting with a IntIndex?

e.g. in below df['date']-df.index should work

This actually DOES work now! (and I take it back, does make some sense)
should df[1]-df.reset_index().index work????

http://stackoverflow.com/questions/18368442/how-to-directly-use-pandas-date-time-index-in-calculations/18368793?noredirect=1#comment26971689_18368793

In [1]: df = DataFrame(randn(5,2),index=date_range('20130101',periods=5))

In [3]: df['date'] = Timestamp('20130102')

In [4]: df
Out[4]: 
                   0         1                date
2013-01-01  2.406932 -0.313473 2013-01-02 00:00:00
2013-01-02  0.034162 -0.708450 2013-01-02 00:00:00
2013-01-03 -1.585031  0.587243 2013-01-02 00:00:00
2013-01-04  1.454818  1.089208 2013-01-02 00:00:00
2013-01-05 -0.778016 -0.994242 2013-01-02 00:00:00

In [5]: df['td'] = df['date']-df.index.to_series()

In [6]: df
Out[6]: 
                   0         1                date                td
2013-01-01  2.406932 -0.313473 2013-01-02 00:00:00  1 days, 00:00:00
2013-01-02  0.034162 -0.708450 2013-01-02 00:00:00          00:00:00
2013-01-03 -1.585031  0.587243 2013-01-02 00:00:00 -1 days, 00:00:00
2013-01-04  1.454818  1.089208 2013-01-02 00:00:00 -2 days, 00:00:00
2013-01-05 -0.778016 -0.994242 2013-01-02 00:00:00 -3 days, 00:00:00

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions