Skip to content

KeyError: 0L with pandas 0.13.1 #6750

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

Closed
stormvirux opened this issue Mar 31, 2014 · 2 comments
Closed

KeyError: 0L with pandas 0.13.1 #6750

stormvirux opened this issue Mar 31, 2014 · 2 comments
Labels
Compat pandas objects compatability with Numpy or Python functions Duplicate Report Duplicate issue or pull request Visualization plotting

Comments

@stormvirux
Copy link

I get the following error

Traceback (most recent call last):
  File "asys.py", line 65, in <module>
    compSub()
  File "asys.py", line 46, in compSub
    plt.hist(data['Total'],linewidth=0, alpha=.7)
  File "/home/storm/Documents/lol/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 2827, in hist
    stacked=stacked, **kwargs)
  File "/home/storm/Documents/lol/local/lib/python2.7/site-packages/matplotlib/axes.py", line 8249, in hist
    if isinstance(x, np.ndarray) or not iterable(x[0]):
  File "/home/storm/Documents/lol/local/lib/python2.7/site-packages/pandas/core/series.py", line 491, in __getitem__
    result = self.index.get_value(self, key)
  File "/home/storm/Documents/lol/local/lib/python2.7/site-packages/pandas/core/index.py", line 1032, in get_value
    return self._engine.get_value(s, k)
  File "index.pyx", line 97, in pandas.index.IndexEngine.get_value (pandas/index.c:2661)
  File "index.pyx", line 105, in pandas.index.IndexEngine.get_value (pandas/index.c:2476)
  File "index.pyx", line 149, in pandas.index.IndexEngine.get_loc (pandas/index.c:3215)
  File "hashtable.pyx", line 382, in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:6450)
  File "hashtable.pyx", line 388, in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:6394)
KeyError: 0L

when I execute the following code(using pandas 0.13.1)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
import statsmodels.api as sm
from numpy.random import randn
import matplotlib as mpl
import seaborn as sns

sns.set_color_palette("deep", desat=.6)
mpl.rc("figure", figsize=(8, 4))

def Compavg():
    data=Total()
    markMax=[]
    markAvg=[]
    N = 5
    ind = np.arange(N)    
    width = 0.35 
    fig = plt.figure()
    ax = fig.add_subplot(111)      
    markMax.extend((data["Total"].max(),data["Total.1"].max(),data["Total.2"].max(),data["Total.3"].max(),data["Total.4"].max()))
    markAvg.extend((data["Total"].mean(),data["Total.1"].mean(),data["Total.2"].mean(),data["Total.3"].mean(),data["Total.4"].mean()))
    rects1 = ax.bar(ind, markMax, width, color='black')
    rects2 = ax.bar(ind+width, markAvg, width, color='green')
    ax.set_xlim(-width,len(ind)+width)
    ax.set_ylim(0,120)
    ax.set_ylabel('Marks')
    ax.set_title('Max, Mean and Your Marks')
    xTickMarks = ['Subject'+str(i) for i in range(1,6)]
    ax.set_xticks(ind+width)
    xtickNames = ax.set_xticklabels(xTickMarks)
    plt.setp(xtickNames, rotation=10, fontsize=10)
    ax.legend( (rects1[0], rects2[0]), ('Max', 'Mean') )
    plt.show()
    print "finished reading 1"

def compSub():
    #max_data = np.r_[data["Total"]].max()
    #bins = np.linspace(0, max_data, max_data + 1)
    data=Total()
        print data['Total']
    plt.hist(data['Total'],linewidth=0, alpha=.7)
    plt.hist(data['Total.1'],linewidth=0,alpha=.7)
    plt.hist(data['Total.2'],linewidth=0,alpha=.7)
    plt.hist(data['Total.3'],linewidth=0,alpha=.7)
    plt.hist(data['Total.4'],linewidth=0,alpha=.7)
    plt.title("Total marks Histogram")
    plt.xlabel("Value")
    plt.ylabel("Frequency")
    plt.show()
        print "finished reading 2"

def Total():
    print "going to read"
    data=pd.read_csv("output11cs.csv")
    df3=data[['Total','Total.1','Total.2','Total.3','Total.4','Total.5','Total.6','Total.7']]
    data["Main Total"]=df3.sum(axis=1)
    data = data.dropna()
    data.reset_index(drop=True)
    print data  
    return data

Compavg()
compSub()

but it works perfectly with pandas version 0.10.0

@jreback
Copy link
Contributor

jreback commented Mar 31, 2014

I think this is a known error with using plt.hist with a Series; either use data['Total.1'].hist()

or pass in the values, e.g. ``plt.hist(data['Total.1'].values,....)

@jreback
Copy link
Contributor

jreback commented Mar 31, 2014

this is a dupe of #6127

basically its an API incompatibility with matplotlib and pandas >= 0.13.

I believe matplotlib is fixing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions Duplicate Report Duplicate issue or pull request Visualization plotting
Projects
None yet
Development

No branches or pull requests

2 participants