Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to ger matching rows data based on index columns
#1
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.
Quote
#2
I didn't try it, but I think it should be something like this:

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

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Knowing the index of a data frame Ivannovix 0 117 Sep-10-2019, 08:22 AM
Last Post: Ivannovix
  How to replace matching rows SriMekala 2 197 Jul-13-2019, 09:43 AM
Last Post: SriMekala
  Mysql returning number of rows not data AkaAndrew123 4 471 Jun-10-2019, 02:31 PM
Last Post: AkaAndrew123
  Loop files - Extract List Data To Individual Columns in CSV dj99 5 375 May-19-2019, 10:29 AM
Last Post: dj99
  How to convert rows to columns. jarrod0987 1 255 May-15-2019, 02:58 AM
Last Post: scidam
  Selecting a sample based on index Scott 1 272 May-14-2019, 08:44 AM
Last Post: Serferi
  How get row index of matching row in column 0 Sri 7 489 Apr-10-2019, 08:26 PM
Last Post: perfringo
  Convert row data to columns based on keyword mjack24 1 216 Feb-18-2019, 06:39 PM
Last Post: micseydel
  Remove Rows based on condition abc123 1 394 Jan-12-2019, 10:45 PM
Last Post: Larz60+
  Print data in rows and columns rlinux57 5 781 Nov-10-2018, 05:50 AM
Last Post: rlinux57

Forum Jump:


Users browsing this thread: 1 Guest(s)