以特定行值循环数据帧的行

2024-05-14 16:21:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我的数据帧包含每个治疗的三个不同复制。我想循环这两种方法,所以我想循环每种治疗方法,并为每种治疗方法计算每个复制的模型。我设法通过治疗循环,但我也需要通过每个治疗的复制循环。理想情况下,输出应保存到包含“治疗”和“复制”的新数据帧中。有什么建议吗

数据帧(df)如下所示:

 treatment replication time  y
  **8          1          1   0.1**
  8          1          2   0.1 
  8          1          3   0.1
  **8          2          1   0.1**
  8          2          2   0.1 
  8          2          3   0.1
  **10         1          1   0.1**
  10         1          2   0.1 
  10         1          3   0.1
  **10         2          1   0.1**
  10         2          2   0.1 
  10         2          3   0.1

for i, g in df.groupby('treament'):
   k = g.iloc[0].y                                   
   popt, pcov = curve_fit(model, x, y)
   fit_m = popt  
   

我现在应用了iterrows,但是我不能再使用NPQ[0]的索引来获取初始值。你知道怎么解决这个问题吗?错误消息的内容如下:

for index, row in HL.iterrows():
  g = (index, row['filename'], row['hr'], row['time'], row['NPQ'])
  k = g.iloc[0]['NPQ'])

AttributeError:“tuple”对象没有属性“iloc”

先谢谢你


Tags: 数据方法in模型dfforindextime

热门问题