【问题标题】:How To Solve KeyError: “None of [Index([..], dtype='object')] are in the [columns]”/KeyError(f"None of [{key}] are in the [{axis_name}]")如何解决 KeyError:“[Index([..], dtype='object')] 均不在 [columns] 中”/KeyError(f"[{key}] 均不在 [{axis_name}] 中")
【发布时间】:2021-08-04 23:39:21
【问题描述】:

我是一名学生,试图为我的班级复制一篇论文的结果。我在重新运行源代码时遇到问题,它返回此错误。我对所有这些模块都很陌生,即使在阅读了这个帖子之后也不太确定如何解决这个问题。 我正在尝试运行 spatial_SeqFISH_analysis.py(在 Analysis/SeqFish/ 中)并返回此错误:

Traceback (most recent call last):

  File "spatial_SeqFISH_analysis.py", line 41, in <module>

    results = main()

  File "spatial_SeqFISH_analysis.py", line 15, in main

    df = df[sample_info.index]

  File "/home/lu003/.local/lib/python3.8/site-packages/pandas/core/frame.py", line 3030, in __getitem__
    indexer = self.loc._get_listlike_indexer(key, axis=1, raise_missing=True)[1]

  File "/home/lu003/.local/lib/python3.8/site-packages/pandas/core/indexing.py", line 1266, in _get_listlike_indexer

    self._validate_read_indexer(keyarr, indexer, axis, raise_missing=raise_missing)

  File "/home/lu003/.local/lib/python3.8/site-packages/pandas/core/indexing.py", line 1308, in _validate_read_indexer

    raise KeyError(f"None of [{key}] are in the [{axis_name}]")

KeyError: 

"None of [Index(['oid sha256:8f40e082985198819ac5a55129272c64d4cf047cc688313b911ead6df82ebae4', 'size 6038'], dtype='object', name='version https://git-lfs.github.com/spec/v1')] are in the [columns]"

我的输入: 我运行了他们的 shell 脚本 rerun_all.sh 并运行了所有的分析 py 文件。 在 spatial_SeqFISH_analysis.py df 和 sample_info 中使用如下:

#pd is pandas

df = pd.read_csv('exp_mat_43.csv', index_col=0) 
df.columns = df.columns.map(int)

# Get coordinates for each sample
sample_info = pd.read_csv('sample_info_43.csv', index_col=0)

df = df[sample_info.index]

X = sample_info[['x', 'y']]

csv 文件包含我认为指向 Git LFS 的指针。例如,这是 sample_info.csv:

version git-lfs.github.com/spec/v1 
oid sha256:a6229820d917eab59582652a5f8ffcf8fa5ed124477ae2dd1046834f6bb5062d 
size 164964

如果有人能提供帮助,那就太好了!

文章链接:https://www.nature.com/articles/nmeth.4636 Github源码:https://github.com/Teichlab/SpatialDE

【问题讨论】:

  • 通常我们要求此处的问题包括一个minimal reproducible example,其中包含您的输入数据帧样本,以便我们可以在上下文中理解问题,而无需访问外部链接。在这种情况下,您可能希望将相关行更改为df = df.iloc[sample_info.index,:],但如果没有样本就很难说。您可以edit 您的问题包括来自dfsample_info 的一些行。您还可以联系论文作者并询问他们代码中的错误
  • 感谢您的意见!我已经编辑了我的帖子。如果您需要额外信息,请告诉我,我可以再次编辑我的帖子。 csv 文件包含我相信指向 github 存储的指针,但我不确定如何访问它们。它看起来像这样:版本git-lfs.github.com/spec/v1oid sha256:a6229820d917eab59582652a5f8ffcf8fa5ed124477ae2dd1046834f6bb5062d 大小 164964。我也已经通过 github 问题向作者发送了消息,但我不确定这是否是获得他们的最佳方式,因为他们还没有解决以前的问题。

标签: python pandas dataframe bioinformatics git-lfs


【解决方案1】:

我想我知道问题所在。由于我没有事先安装 git-lfs,所以 csv 文件作为指向存储的指针留下。然而,遗憾的是,重新克隆 repo 后,lfs 文件太大,我仍然无法运行代码。

这是克隆后返回的:

 This repository is over its data quota. Account responsible for LFS bandwidth should purchase more data packs to restore access.

【讨论】:

    猜你喜欢
    • 2021-01-08
    • 1970-01-01
    • 1970-01-01
    • 2022-11-18
    • 2019-09-16
    • 2021-08-14
    • 2021-01-11
    • 2021-04-01
    • 2023-01-30
    相关资源
    最近更新 更多