Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raise ValueError"cannot reindex from a duplicate axis" #11

Open
wenyl1919 opened this issue Aug 4, 2021 · 3 comments
Open

raise ValueError"cannot reindex from a duplicate axis" #11

wenyl1919 opened this issue Aug 4, 2021 · 3 comments

Comments

@wenyl1919
Copy link

HI, when i run the following command, i encounter the following error:

import anndata
import scvelo as scv
import pandas as pd
import numpy as np
import matplotlib as plt

C183 = anndata.read_loom("C183.loom",validate=False)
C184 = anndata.read_loom("C184.loom",validate=False)
C185 = anndata.read_loom("C185.loom",validate=False)

sample_obs = pd.read_csv("hspc.three.cellID_obs.csv")
umap_cord = pd.read_csv("hspc.three.cell_embeddings.csv")
cell_clusters = pd.read_csv("hspc.three.clusters.csv")

C183.obs=C183.obs.rename(index = lambda x: x.replace('C183:', ''))
C183.obs=C183.obs.rename(index = lambda x: x.replace('x', ''))
C183.obs.head()

C184.obs=C184.obs.rename(index = lambda x: x.replace('C184:', ''))
C184.obs=C184.obs.rename(index = lambda x: x.replace('x', ''))
C184.obs.head()

C185.obs=C185.obs.rename(index = lambda x: x.replace('C185:', ''))
C185.obs=C185.obs.rename(index = lambda x: x.replace('x', ''))
C185.obs.head()

sample_obs.x=sample_obs.x.replace({"C183_":""},regex=True)
sample_obs.x=sample_obs.x.replace({"C184_":""},regex=True)
sample_obs.x=sample_obs.x.replace({"C185_":""},regex=True)

C183 = C183[np.isin(C183.obs.index,sample_obs["x"])]

C184 = C184[np.isin(C184.obs.index,sample_obs["x"])]

C185 = C185[np.isin(C185.obs.index,sample_obs["x"])]

###merge file

sample_one = C183.concatenate(C183,C184,C185)

the error as following:
Traceback (most recent call last):
File "", line 1, in
File "/home/wenyl/miniconda3/lib/python3.8/site-packages/anndata/_core/anndata.py", line 1757, in concatenate
out = concat(
File "/home/wenyl/miniconda3/lib/python3.8/site-packages/anndata/_core/merge.py", line 81 8, in concat
alt_annot = merge_dataframes(
File "/home/wenyl/miniconda3/lib/python3.8/site-packages/anndata/_core/merge.py", line 53 1, in merge_dataframes
dfs = [df.reindex(index=new_index) for df in dfs]
File "/home/wenyl/miniconda3/lib/python3.8/site-packages/anndata/_core/merge.py", line 53 1, in
dfs = [df.reindex(index=new_index) for df in dfs]
File "/home/wenyl/miniconda3/lib/python3.8/site-packages/pandas/util/_decorators.py", lin e 324, in wrapper
return func(*args, **kwargs)
File "/home/wenyl/miniconda3/lib/python3.8/site-packages/pandas/core/frame.py", line 4767 , in reindex
return super().reindex(**kwargs)
File "/home/wenyl/miniconda3/lib/python3.8/site-packages/pandas/core/generic.py", line 48 09, in reindex
return self._reindex_axes(
File "/home/wenyl/miniconda3/lib/python3.8/site-packages/pandas/core/frame.py", line 4592 , in _reindex_axes
frame = frame._reindex_index(
File "/home/wenyl/miniconda3/lib/python3.8/site-packages/pandas/core/frame.py", line 4611 , in _reindex_index
return self._reindex_with_indexers(
File "/home/wenyl/miniconda3/lib/python3.8/site-packages/pandas/core/generic.py", line 48 74, in _reindex_with_indexers
new_data = new_data.reindex_indexer(
File "/home/wenyl/miniconda3/lib/python3.8/site-packages/pandas/core/internals/managers.p y", line 663, in reindex_indexer
self.axes[axis]._validate_can_reindex(indexer)
File "/home/wenyl/miniconda3/lib/python3.8/site-packages/pandas/core/indexes/base.py", li ne 3785, in _validate_can_reindex
raise ValueError("cannot reindex from a duplicate axis")

I checked the cellid of three samples and found no same. I didin't know how to fix.

@JoshuaCumming
Copy link

Hi,

I am having the same issue. Did you find a solution?

@wenyl1919
Copy link
Author

wenyl1919 commented Aug 18, 2021 via email

@JoshuaCumming
Copy link

This fixed it, thanks :)

Best,

JC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants