Skip to content Skip to sidebar Skip to footer

How Do I Compare Two Dataframe Using Between Function On The Other Dataframe

i have a dataframe that looks like this : Words Start_time(in sec) End_time(in secs) Total_Time_words 0 let 0.1 2.5 2.6

Solution 1:

You can use pd.cut and groupby():

bins = [df['Start_time(in sec)'].iloc[0]] + list(df['End_time(in secs)'])
s = pd.cut(df2.Time, bins=bins, labels=df.index)

df['Amplitudes'] = (df2.sort_values('Amplitudes', ascending=False)
                       .groupby(s)['Amplitudes']
                       .apply(lambda x: x.head(5).mean())
                   )

Output:

   Words  Start_time(in sec)  End_time(in secs)  Total_Time_words  Amplitudes
0    let                 0.12.52.60.0015461     me                 2.52.65.1NaN2   tell                 2.62.95.5NaN3    you                 2.93.05.9NaN4  about                 3.03.26.2NaN

Post a Comment for "How Do I Compare Two Dataframe Using Between Function On The Other Dataframe"