pandas/index.pyx in pandas.index.IndexEngine.get_loc - KeyError - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: pandas/index.pyx in pandas.index.IndexEngine.get_loc - KeyError (/thread-936.html) |
pandas/index.pyx in pandas.index.IndexEngine.get_loc - KeyError - jacobs.smith - Nov-15-2016 Dear All, Here is my python script import pandas as pd import numpy as np from matplotlib import pyplot as plt from matplotlib import style style.use('ggplot') import lzma import feather import json from urllib import request exec(request.urlopen('/master/tailseeker/stats.py').read().decode()) exec(request.urlopen('/master/tailseeker/plotutils.py').read().decode()) %cd /home/work/tagcounts/ SAMPLES = 'S1 S2 S3 S4 S5'.split() tagcounts = { sample: pd.read_msgpack(lzma.open(sample + '-single-U-canonical.msgpack.xz', 'rb')) for sample in SAMPLES } genedb=feather.read_dataframe('/home/work/annotations-gene.feather').set_index('gene_id') GENES_TO_PLOT = 'Ager Agk Agl Afp'.split() gene_ids = genedb[genedb['gene_name'].isin(GENES_TO_PLOT)]['gene_name'] gene_ids len(gene_ids) COLORS = colormap_lch(len(gene_ids), end=200, lum=50) COLORS len(COLORS) fig, axes = plt.subplots(len(gene_ids), 1, figsize=(6, 7)) xpts = np.arange(0, 16.1, 0.1) xticks = np.arange(0, 16.1, 2) xticklabels = (xticks ** 2).astype(int) for (gene_id, gene_name), ax in zip(gene_ids.items(), axes): ax.set_title(gene_name) for s, color in zip(SAMPLES, COLORS): tcnt = tagcounts[s][gene_id].sum(axis=1) kde = gaussian_kde(tcnt.index ** 0.5,weights=np.array(tcnt), bw_method=0.1) ax.plot(xpts, kde(xpts), c=color, label=s) ax.set_xticks(xticks) ax.set_xticklabels(xticklabels) ax.set_ylabel('Density') ax.set_xlabel('Poly(A) length') ax.legend(loc='best', fontsize=10) plt.tight_layout()The output of gene_ids is like this gene_id ENSMUSG00000015452.14 Ager ENSMUSG00000029916.11 Agk ENSMUSG00000033400.14 Agl ENSMUSG00000054932.6 Afp Name: gene_name, dtype: object Here is the error URL was edited because this is my first post. But the URL in exec.code section was working fine. No issues with it. I downgraded pandas from 0.19.1 to 0.17.0 and the error still persists. All pointers/comments/suggestions/solutions are appreciated. Thanks in advance.
RE: pandas/index.pyx in pandas.index.IndexEngine.get_loc - KeyError - jacobs.smith - Nov-15-2016 The data frame sizes of the variable tagcounts are like this {'S1: <class 'pandas.core.panel.Panel'> Dimensions: 2343 (items) x 230 (major_axis) x 21 (minor_axis) Items axis: ENSMUSG00000000049.11 to ENSMUSG00000109482.1 Major_axis axis: 0 to 229 Minor_axis axis: 0 to 20, 'S2': <class 'pandas.core.panel.Panel'> Dimensions: 1549 (items) x 230 (major_axis) x 21 (minor_axis) Items axis: ENSMUSG00000000049.11 to ENSMUSG00000109482.1 Major_axis axis: 0 to 229 Minor_axis axis: 0 to 20, 'S3': <class 'pandas.core.panel.Panel'> Dimensions: 2078 (items) x 230 (major_axis) x 21 (minor_axis) Items axis: ENSMUSG00000000049.11 to ENSMUSG00000109511.1 Major_axis axis: 0 to 229 Minor_axis axis: 0 to 20, 'S4': <class 'pandas.core.panel.Panel'> Dimensions: 2784 (items) x 230 (major_axis) x 21 (minor_axis) Items axis: ENSMUSG00000000001.4 to ENSMUSG00000109093.1 Major_axis axis: 0 to 229 Minor_axis axis: 0 to 20, 'S5': <class 'pandas.core.panel.Panel'> Dimensions: 1576 (items) x 230 (major_axis) x 21 (minor_axis) Items axis: ENSMUSG00000000049.11 to ENSMUSG00000107283.3 Major_axis axis: 0 to 229 Minor_axis axis: 0 to 20} RE: pandas/index.pyx in pandas.index.IndexEngine.get_loc - KeyError - nilamo - Nov-17-2016 If the error is internal to pandas, you should probably report it to them and/or file a bug report so they can fix it. |