Python Forum

Full Version: How to ger matching rows data based on index columns
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have below pandas dataframe,
df1: 
[python]
                A         B         C         D
2000-01-01  0.469112 -0.282863 -1.509059 -1.135632
2000-01-02  1.212112 -0.173215  0.119209 -1.044236
2000-01-03 -0.861849 -2.104569 -0.494929  1.071804
2000-01-04  0.721555 -0.706771 -1.039575  0.271860
2000-01-05 -0.424972  0.567020  0.276232 -1.087401
2000-01-06 -0.673690  0.113648 -1.478427  0.524988
2000-01-07  0.404705  0.577046 -1.715002 -1.039268
2000-01-08 -0.370647 -1.157892 -1.344312  0.844885
df2:

                   A         B         C         D
2000-01-01  0.409571  0.113086 -0.610826 -0.936507
2000-01-03  1.152571  0.222735  1.017442 -0.845111
2000-01-05 -0.921390 -1.708620  0.403304  1.270929
2000-01-07  0.662014 -0.310822 -0.141342  0.470985
2000-01-09 -0.733231  0.509598 -0.580194  0.724113
I want get the row index where index of df2 is exactly equal to df2 index.
In this case
row0,row2,row4,row6 (assumed that rows are numbered from 0,1,2,3,4,5,6,7,8,9 etc)
I want the output as

2000-01-01  0.469112 -0.282863 -1.509059 -1.135632
2000-01-03 -0.861849 -2.104569 -0.494929  1.071804
2000-01-05 -0.424972  0.567020  0.276232 -1.087401
2000-01-07  0.404705  0.577046 -1.715002 -1.039268
Can some one help me how get the matching rows data based on index column.
I didn't try it, but I think it should be something like this:

df1.ix[df2.index].dropna()