Python Forum
How to ger matching rows data based on index columns
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.
Reply
#2
I didn't try it, but I think it should be something like this:

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Changing client.get() method type based on size of data... dl0dth 1 1,273 Jan-02-2025, 08:30 PM
Last Post: dl0dth
  Matching Data - Help - Dictionary manuel174102 1 1,564 Feb-02-2024, 04:47 PM
Last Post: deanhystad
  how do you style data frame that has empty rows. gsaray101 0 1,471 Sep-08-2023, 05:20 PM
Last Post: gsaray101
  Grouping Data based on 30% bracket purnima1 4 2,807 Mar-10-2023, 07:38 PM
Last Post: deanhystad
  Converting a json file to a dataframe with rows and columns eyavuz21 13 20,232 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  (Python) Pulling data from UA Google Analytics with more than 100k rows into csv. Stockers 0 2,386 Dec-19-2022, 11:11 PM
Last Post: Stockers
  Extracting Data into Columns using pdfplumber arvin 17 36,785 Dec-17-2022, 11:59 AM
Last Post: arvin
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 5,261 Dec-12-2022, 08:22 PM
Last Post: jh67
  Check DataFrames with different sorting in columns and rows Foxyskippy 0 1,532 Nov-19-2022, 07:49 AM
Last Post: Foxyskippy
  Deleting rows based on cell value in Excel azizrasul 11 8,402 Oct-19-2022, 02:38 AM
Last Post: azizrasul

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.