ValueError: cannot reindex from a duplicate axis when merge.
akui113 opened this issue · 5 comments
@basilkhuder
Hi, Basil
it's perfect work, but i was confused with one inssue as following,
Dataprocess:
sample_obs = pd.read_csv("cellID.csv")
#I extracted Cell IDs from Seurat, and filtered uploaded loom.
sample_one = sample_one[np.isin(sample_one.obs.index, sample_obs["x"])]
sample_two= sample_two[np.isin(sample_two.obs.index, sample_obs["x"])]
#then, we merged them into one, but get the error,
sample_one = sample_one.concatenate(sample_two, sample_three, sample_four)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/anaconda3/envs/epigenetic/lib/python3.8/site-packages/anndata/_core/anndata.py", line 1696, in concatenate
out = concat(
File "/usr/local/anaconda3/envs/epigenetic/lib/python3.8/site-packages/anndata/_core/merge.py", line 814, in concat
alt_annot = merge_dataframes(
File "/usr/local/anaconda3/envs/epigenetic/lib/python3.8/site-packages/anndata/_core/merge.py", line 526, in merge_dataframes
dfs = [df.reindex(index=new_index) for df in dfs]
File "/usr/local/anaconda3/envs/epigenetic/lib/python3.8/site-packages/anndata/_core/merge.py", line 526, in
dfs = [df.reindex(index=new_index) for df in dfs]
File "/usr/local/anaconda3/envs/epigenetic/lib/python3.8/site-packages/pandas/util/_decorators.py", line 312, in wrapper
return func(*args, **kwargs)
File "/usr/local/anaconda3/envs/epigenetic/lib/python3.8/site-packages/pandas/core/frame.py", line 4173, in reindex
return super().reindex(**kwargs)
File "/usr/local/anaconda3/envs/epigenetic/lib/python3.8/site-packages/pandas/core/generic.py", line 4808, in reindex
return self._reindex_axes(
File "/usr/local/anaconda3/envs/epigenetic/lib/python3.8/site-packages/pandas/core/frame.py", line 4019, in _reindex_axes
frame = frame._reindex_index(
File "/usr/local/anaconda3/envs/epigenetic/lib/python3.8/site-packages/pandas/core/frame.py", line 4038, in _reindex_index
return self._reindex_with_indexers(
File "/usr/local/anaconda3/envs/epigenetic/lib/python3.8/site-packages/pandas/core/generic.py", line 4874, in _reindex_with_indexers
new_data = new_data.reindex_indexer(
File "/usr/local/anaconda3/envs/epigenetic/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 1301, in reindex_indexer
self.axes[axis]._can_reindex(indexer)
File "/usr/local/anaconda3/envs/epigenetic/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 3476, in _can_reindex
raise ValueError("cannot reindex from a duplicate axis")
ValueError: cannot reindex from a duplicate axis
So, how can I fix this problem?
Thank you for your generous help!
@basilkhuder I have been fixed this issue, Thank you!
Hi @akui113, sorry I couldn't reply in time, but happy to see you have resolved the error!
@akui113 Hi! I am encountering the same problem. Can I know how you fixed this issue?
@nicodemus88 Hi, I changed the cellID to make it consistent. You can refer to the website https://www.jianshu.com/p/9ba064a41227.
@nicodemus88 Hi, I changed the cellID to make it consistent. You can refer to the website https://www.jianshu.com/p/9ba064a41227.
I check all cellID of sample and found there is no same cellID among samples. I don't know how to fix the problem.