DEV Community

brhett
brhett

Posted on

Answer: Apply find_peaks() function using groupby() in a pandas dataframe

import pandas as pd
import numpy as np
from scipy.signal import find_peaks
def find_peaks_in_group(group):
    # Find peaks
    peaks, peak_properties = find_peaks(group['RFPower'], prominence=1, height=0.7)
    
    # Initialize columns to store peak data
    group['peaks'] = False
    group['peak_heights'] = 0.0
    
    # Use iloc to correctly assign values based on relative indices
    if len(peaks) >

Top comments (0)