You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Jupyter Notebook中使用特定pandas版本适配methylprep?

AttributeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_9268\2686656903.py in ?()
----> 1 data_containers = methylprep.run_pipeline(filepath, array_type=None, export=True, manifest_filepath=None, sample_sheet_filepath='test/MethylationEPIC_Sample_Sheet_B.csv')

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\methylprep\processing\pipeline.py in ?(data_dir, array_type, export, manifest_filepath, sample_sheet_filepath, sample_name, betas, m_value, make_sample_sheet, batch_size, save_uncorrected, save_control, meta_data_frame, bit, poobah, export_poobah, poobah_decimals, poobah_sig, low_memory, sesame, quality_mask, pneg_ecdf, file_format, **kwargs)
327
328 batch_data_containers = []
329 export_paths = set() # inform CLI user where to look
330 for idat_dataset_pair in tqdm(idat_datasets, total=len(idat_datasets), desc="Processing samples"):
--> 331 data_container = SampleDataContainer(
332 idat_dataset_pair=idat_dataset_pair,
333 manifest=manifest,
334 retain_uncorrected_probe_intensities=save_uncorrected,

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\methylprep\processing\pipeline.py in ?(self, idat_dataset_pair, manifest, retain_uncorrected_probe_intensities, bit, pval, poobah_decimals, poobah_sig, do_noob, quality_mask, switch_probes, do_nonlinear_dye_bias, debug, sesame, pneg_ecdf, file_format)
586 self.manifest = manifest # used by inter_channel_switch only.
587 if self.switch_probes:
588 # apply inter_channel_switch here; uses raw_dataset and manifest only; then updates self.raw_dataset
589 # these are read from idats directly, not SigSet, so need to be modified at source.
--> 590 infer_type_I_probes(self, debug=self.debug)
591
592 super().init(self.sample, self.green_idat, self.red_idat, self.manifest, self.debug)
593 # SigSet defines all probe-subsets, then SampleDataContainer adds them with super(); no need to re-define below.

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\methylprep\processing\infer_channel_switch.py in ?(container, debug)
15 -- runs in SampleDataContainer.init this BEFORE qualityMask step, so NaNs are not present
16 -- changes raw_data idat probe_means
17 -- runs on raw_dataset, before meth-dataset is created, so @IR property doesn't exist yet; but get_infer has this"""
18 # this first step combines all I-red and I-green channel intensities, so IG+oobG and IR+oobR.
---> 19 channels = get_infer_channel_probes(container.manifest, container.green_idat, container.red_idat, debug=debug)
20 green_I_channel = channels['green']
21 red_I_channel = channels['red']
22 ## NAN probes occurs when manifest is not complete

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\methylprep\processing\infer_channel_switch.py in ?(manifest, green_idat, red_idat, debug)
167 red_in_band['meth'] = oobG_unmeth
168 green_in_band['unmeth'] = oobR_meth
169
170 # next, add the green-in-band to oobG and red-in-band to oobR
--> 171 oobG_IG = oobG.append(green_in_band).sort_index()
172 oobR_IR = oobR.append(red_in_band).sort_index()
173
174 # channel swap requires a way to update idats with illumina_ids

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\generic.py in ?(self, name)
6295 and name not in self._accessors
6296 and self._info_axis._can_hold_identifiers_and_holds_name(name)
6297 ):
6298 return self[name]
-> 6299 return object.getattribute(self, name)

AttributeError: 'DataFrame' object has no attribute 'append'

## 解决方法
可以使用指定版本的pandas兼容methylprep,推荐用虚拟环境隔离依赖,避免影响全局环境:

### 1. 创建并激活虚拟环境
- 打开终端(Windows用CMD/PowerShell),创建虚拟环境:
  ```bash
  python -m venv methylenv
  • 激活环境:
    • Windows:
      methylenv\Scripts\activate
      
    • macOS/Linux:
      source methylenv/bin/activate
      

2. 安装兼容版本的依赖

注意:pandas没有1.8版本,最后一个支持DataFrame.append()的大版本是1.5.x,这里用1.5.3:

pip install pandas==1.5.3 methylprep

3. 在Jupyter Notebook中使用该环境

  • 激活环境后安装ipykernel:
    pip install ipykernel
    
  • 将环境添加到Jupyter内核:
    python -m ipykernel install --user --name=methylenv
    
  • 打开Notebook,右上角选择methylenv内核运行脚本即可。

临时测试方案(不推荐)

如果不想用虚拟环境,可临时修改methylprep源码:找到报错的infer_channel_switch.py文件,将第171、172行的append()替换为pd.concat():

# 原代码
oobG_IG = oobG.append(green_in_band).sort_index()
oobR_IR = oobR.append(red_in_band).sort_index()

# 修改后
import pandas as pd
oobG_IG = pd.concat([oobG, green_in_band]).sort_index()
oobR_IR = pd.concat([oobR, red_in_band]).sort_index()

这种方法会修改库文件,更新methylprep后失效,仅适合临时测试。

内容的提问来源于stack exchange,提问作者Isaac P. Liu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 00:14:51