简体   繁体   中英

Return the index of a row based on value in different dataframe's row

I have two Pandas dataframes. They all contain 3 decimal point float values.

Dataframe A is a one column dataframe with 12 rows. Dataframe B is a one column dataframe with over 40,000 rows, which contain the 12 values in Dataframe A spread out randomly.

I need to find the indices of the values in Dataframe A within Dataframe B.

I have tried .query() , .index.value() and .where() but am unable to return the indices.

Dataframe A

Row Index Time
0 148.521
1 112.379
... ...
12 510.121

Dataframe B

Row Index Time
0 0.000
1 0.025
... ...
46871 1171.675

You can use df.loc[]

for i in dataframe_A['Time']:
  dataframe_B.loc[dataframe_B['Time'] == i]

This should return the twelve values along with their row index from dataframe B

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM