Skip to content

Instantly share code, notes, and snippets.

@dberkholz
Last active August 29, 2015 14:11
Show Gist options
  • Save dberkholz/7d66deb2f50b47d72785 to your computer and use it in GitHub Desktop.
Save dberkholz/7d66deb2f50b47d72785 to your computer and use it in GitHub Desktop.
Weekly clustering of timestamps with pandas
#!/usr/bin/env python
import pandas as pd, numpy as np
d = pd.read_table('input.txt', skiprows=0, header=None, parse_dates=True, index_col=0)
d['values'] = np.ones(len(d))
e = d.resample('w', how='sum')
f = e.fillna(value=0)
f.to_csv('output_weekly.txt', sep='\t')
#import matplotlib as mpl
#f.plot()
#mpl.pyplot.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment