You can use the Index.Intersection for finding the common indexing columns.
a = pd.DatetimeIndex(['2000-12-31T00:00:00.000000000',
'2001-12-31T00:00:00.000000000',
'2002-12-31T00:00:00.000000000',
'2003-12-31T00:00:00.000000000'])
b = pd.DatetimeIndex(['1947-12-31T00:00:00.000000000',
'1948-12-31T00:00:00.000000000',
'1997-12-31T00:00:00.000000000',
'1998-12-31T00:00:00.000000000',
'1999-12-31T00:00:00.000000000',
'2000-12-31T00:00:00.000000000',
'2001-12-31T00:00:00.000000000',
'2002-12-31T00:00:00.000000000'])
df1 = pd.DataFrame(index=a)
df2 = pd.DataFrame(index=b)
common_dates = list(set(df1.index.values).intersection(df2.index.values))
print(common_dates)
[numpy.datetime64('2000-12-31T00:00:00.000000000'),
numpy.datetime64('2001-12-31T00:00:00.000000000'),
numpy.datetime64('2002-12-31T00:00:00.000000000')]
You can also use the loc function in order to select columns using numbers as shown below in the below code.
common_dates = df1.index.intersection(df2.index)
print(common_dates)
DatetimeIndex(['2000-12-31', '2001-12-31', '2002-12-31'],
dtype='datetime64[ns]', freq='A-DEC')
df1= df1.loc[common_dates]
df2= df2.loc[common_dates]
print (df1)
Empty DataFrame
Columns: []
Index: [2000-12-31 00:00:00, 2001-12-31 00:00:00, 2002-12-31 00:00:00]
print (df2)
Empty DataFrame
Columns: []
Index: [2000-12-31 00:00:00, 2001-12-31 00:00:00, 2002-12-31 00:00:00]