【问题标题】:How to find local maxima for all the rows of a dataframe?如何找到数据框所有行的局部最大值?
【发布时间】:2020-01-19 03:55:22
【问题描述】:
print(df.head())

from scipy.signal import argrelextrema

ilocs_max = []

for i in range (df.shape[0]):

ilocs_max.append(argrelextrema(df.iloc[i,:].values, np.greater_equal, order=15))

df.iloc[0,:].plot(figsize=(20,8))
df.iloc[3000,:].plot(figsize=(20,8))
df.iloc[3000, [df.loc[3000].tolist()]].plot(style='.', lw=10, color='red', marker="v")

【问题讨论】:

    标签: python-3.x pandas list object scipy


    【解决方案1】:

    从 scipy.signal 导入 argrelextrema

    ilocs_max = []

    for i in range (df.shape[0]):
    
    ilocs_max.append(argrelextrema(df.iloc[i,:].values, np.greater_equal, order=15))
    
    #Creat a new dataframe of ilocs_max
    df1 = pd.DataFrame(ilocs_max)
    
    df.iloc[0,:].plot(figsize=(20,8))
    df.iloc[3000,:].plot(figsize=(20,8))
    df.iloc[3000, df1.iloc[3000].tolist()].plot(style='.', lw=10, color='red', marker="v"
    

    【讨论】:

      【解决方案2】:
      df.reset_index(drop = True, inplace = True)
      
      max_list = [] 
      
      for i in range(len(df)):
          max_list.append(df.loc[i].max())
      

      【讨论】:

      • 请考虑在您的答案中添加一些解释或细节。虽然它可能会回答问题,但只是添加一段代码作为答案,并不能帮助 OP 或未来的社区成员理解问题或建议的解决方案。
      猜你喜欢
      • 1970-01-01
      • 2021-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-09
      • 2011-10-31
      • 2019-07-13
      相关资源
      最近更新 更多