Skip to content

Instantly share code, notes, and snippets.

@lenolib
Last active October 5, 2015 11:20
Show Gist options
  • Save lenolib/f50e7129f2456dd458a2 to your computer and use it in GitHub Desktop.
Save lenolib/f50e7129f2456dd458a2 to your computer and use it in GitHub Desktop.
from IPython.core.history import HistoryAccessor
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
hist_access = HistoryAccessor()
start_times, n_cmds = zip(*list(hist_access.db.execute('select start, num_cmds from sessions')))
num_cmds = pd.Series(n_cmds, index=start_times)
cmds_hod = num_cmds.groupby(num_cmds.index.hour).agg(sum)
starts = pd.Series(np.ones(len(start_times)), index=start_times)
starts_hod = starts.groupby(starts.index.hour).agg(sum)
starts_prob = starts_hod / starts.sum()
title_text = 'ipython session start probabilities (hour of day) (Total starts: {})'.format(starts.sum())
starts_prob.plot(title=title_text, kind='bar')
plt.gcf().show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment