2016-03-05 4 views
0

У меня есть лист первенствовать, содержащий три вещи, которые я хочу, чтобы построить из трех раз (24, 48 и 72h):проблемы Гистограмма в Python

test = pd.read_excel(excel_sheet_location) 
times = ('24h', '48h', '72h') 

и выборки данных выглядит следующим образом:

thing1 thing2 Time 
38.655 8.655 24h  
18.385 8.655 24h  
26.013 8.655 24h  ... 

Так что я пытаюсь сделать 3 гистограмм для каждой временной точки со следующим кодом:

for i in range(2): 
    fig, ax = plt.subplots(1, 2, sharex=True, sharey=True, figsize=(8,3)) 

    idx = (test["Time"] == t) 

    ax[i].hist(test.ix[idx,'thing1'],range(51),normed=True,linewidth=0) 

однако, его рисует первую гистограмму, а затем подбрасывает эти ошибки:

pandas/index.pyx in pandas.index.IndexEngine.get_value (pandas/index.c:3113)() 
pandas/index.pyx in pandas.index.IndexEngine.get_value (pandas/index.c:2844)() 
pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:3704)() 
pandas/hashtable.pyx in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:7224)() 
pandas/hashtable.pyx in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:7162)() 

KeyError: 0 

Каждый получил какие-либо идеи относительно того, почему он это делает? Фактические данные прекрасны (я проверил, обменивая значения на листе и проделал ту же ошибку).

ответ

1

Не уверен, что смогу следовать вашей ошибке (возможно, вам просто нужно обновить до более новой версии панд), или вы сделаете что-то странное, чтобы получить от times до t.

Если я использую:

times = ['24h','48h'] 

# Create the figure outside the loop 
fig, ax = plt.subplots(1, 2, sharex=True, sharey=True, figsize=(8,3)) 

# If you want 3 plots you need to change this to range(3) and the subplots above to (1, 3, ...) 
for i in range(2): 
    # Index the times list instead of the ominous t variable 
    idx = (test["Time"] == times[i]) 
    ax[i].hist(test.ix[idx,'thing1'], range(51), normed=True, linewidth=0) 

plt.show() 

он работает (только некоторые случайные данные):

enter image description here

Смежные вопросы