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 1 298 May-01-2020, 02:51 PM
Last Post: klllmmm
  How to extract specific rows and columns from a text file with Python Farhan 0 237 Mar-25-2020, 09:18 PM
Last Post: Farhan
  Filtering Excel Document Data Based On Numerical Values eddywinch82 30 2,640 Feb-25-2020, 06:08 PM
Last Post: eddywinch82
  Arrange my looped template data in rows JedBoyle 0 156 Feb-19-2020, 01:41 PM
Last Post: JedBoyle
  How to get row row index of matching row SriRajesh 0 134 Feb-13-2020, 02:35 PM
Last Post: SriRajesh
  Do Calculation between Rows based on Column values - Pandas Dataframe ahmedwaqas92 0 281 Jan-28-2020, 07:06 AM
Last Post: ahmedwaqas92
  Python Based Data QA Automation tool suggestion Sonia567 1 236 Nov-19-2019, 04:46 PM
Last Post: Larz60+
  How to replace matching rows SriMekala 2 389 Jul-13-2019, 09:43 AM
Last Post: SriMekala
  Mysql returning number of rows not data AkaAndrew123 4 675 Jun-10-2019, 02:31 PM
Last Post: AkaAndrew123
  Loop files - Extract List Data To Individual Columns in CSV dj99 5 655 May-19-2019, 10:29 AM
Last Post: dj99

Forum Jump:


Users browsing this thread: 1 Guest(s)