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
The index object has some set-like properties so you simply can take the intersection as follows:
df1 = df1.reindex[ df1.index & df2.index ]
This retains the order of the first dataframe in the intersection, df.
df