1

I have two DataFrames with TimesSeriesIndex, df1, df2.

df2's index is a subset of df1.index.
How can I extract the index dates from df1 which also contained by df2, so I can run analysis on these dates.

1 Answer 1

1

Take the intersection of their indices.

In [1]: import pandas as pd

In [2]: index1 = pd.DatetimeIndex(start='2000-1-1', freq='1T', periods=1000000)

In [3]: index2 = pd.DatetimeIndex(start='2000-1-1', freq='1D', periods=1000)

In [4]: index1
Out[4]: 

[2000-01-01 00:00:00, ..., 2001-11-25 10:39:00]
Length: 1000000, Freq: T, Timezone: None

In [5]: index2
Out[5]: 

[2000-01-01 00:00:00, ..., 2002-09-26 00:00:00]
Length: 1000, Freq: D, Timezone: None

In [6]: index1 & index2
Out[6]: 

[2000-01-01 00:00:00, ..., 2001-11-25 00:00:00]
Length: 695, Freq: D, Timezone: None

In your case, do the following:

index1 = df1.index
index2 = df2.index

Then take the intersection of these as defined before. Later you may wish to do something like the following to get the df at intersection index.

df1_intersection =df1.ix[index1 & index2]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.