1

I have a master Dataframe as:

Time Frq Seq 12:46:17 4200.0 30700.0 12:49:29 4160.0 30690.0 12:46:18 3060.0 30700.0 12:46:18 3060.0 30700.0 12:46:19 3060.0 30700.0 12:46:20 3060.0 30700.0 12:46:20 4240.0 30700.0 12:46:19 4220.0 30700.0 12:46:18 4200.0 30700.0 12:46:18 4200.0 30700.0 12:46:38 3060.0 30700.0 12:43:04 4620.0 30701.0 12:46:38 4600.0 30701.0 12:46:05 4600.0 30701.0 12:46:37 3060.0 30700.0 12:48:35 3020.0 30690.0 

and a child Dataframe as:

Frq Seq 3060.0 30700.0 4600.0 30701.0 

I want to collect the 1st occurrence of the Child Dataframe rows in Master Dataframe.

I want my Result Dataframe as:

Time Frq Seq 12:46:18 3060.0 30700.0 12:46:38 4600.0 30701.0 
1
  • 1
    if time col is sorted, can you try master.merge(child,on='Frq',suffixes=('','_')).groupby('Frq',as_index=False).first().reindex(master.columns,axis=1) ? Commented Sep 27, 2019 at 4:41

3 Answers 3

1

First remove duplicated in master by DataFrame.drop_duplicates and then use DataFrame.merge - if omit parameter on it merge by intersection of columns names between both DataFrames:

df = master.drop_duplicates(['Frq','Seq']).merge(child) print (df) Time Frq Seq 0 12:46:18 3060.0 30700.0 1 12:46:38 4600.0 30701.0 
Sign up to request clarification or add additional context in comments.

Comments

0

my approach would be grouping to get the firsts of each group to then index for the elements in your child dataframe:

first = master.groupby('Frq', as_index=False).first() first[first.Frq.isin(child.Frq)] # Frq Time Seq # 1 3060.0 12:46:18 30700.0 # 6 4600.0 12:46:38 30701.0 

Comments

0
  • pd.merge() - to merge master dataframe and child dataframe with inner join.

  • .drop_duplicate() - drop all duplicate row which has Frq and Seq column value is duplicate and keep only first-row value.

  • df.reset_index() - Reset the index, or a level of it.

Ex.

df = master.merge(child, on=['Frq','Seq'], how='inner').drop_duplicates(['Frq','Seq'],keep= 'first').reset_index(drop=True) print(df) Time Frq Seq 0 12:46:18 3060.0 30700.0 1 12:46:38 4600.0 30701.0 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.