I have two pandas DataFrames df1 and df2 and I want to transform them in order that they keep values only for the index that are common to the 2 dataframes.
df1
And, using isin
. intersection
might be faster though.
In [286]: df1.loc[df1.index.isin(df2.index)]
Out[286]:
values1
0
28/11/2000 -0.055276
29/11/2000 0.027427
30/11/2000 0.066009
In [287]: df2.loc[df2.index.isin(df1.index)]
Out[287]:
values2
0
28/11/2000 -0.026316
29/11/2000 0.015222
30/11/2000 -0.024480