Skip to content

Instantly share code, notes, and snippets.

@alfard
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfard/c82a653ae327890aa4fe to your computer and use it in GitHub Desktop.
Save alfard/c82a653ae327890aa4fe to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import datetime
import numpy as np
from ggplot import *
import pandas as pd
#####################################################################
z=np.load("/home/alfard/Documents/Course/twitter/hidal26.npy")
b1=[]
for i in range(0, len(z)):
if (z[i,0].day>25) and (z[i,0].day<31):
b1.append([z[i,0].day,z[i,0].hour,1])
c1=pd.DataFrame(b1)
e1=c1.groupby([0,1], as_index=False).aggregate(np.sum)
e1=np.array(e1)
e1=e1[12:119]
#####################################################################
e=np.array([datetime.datetime(2014,3,e1[i,0],e1[i,1]) for i in range(len(e1))])
e=pd.DataFrame(e)
e1=pd.DataFrame(e1)
#####################################################################
e3=pd.merge(e,e1, on=e.index)
#####################################################################
y=np.load("/home/alfard/Documents/Course/twitter/NKM26.npy")
b=[]
for i in range(0, len(y)):
if (y[i,0].day>25) and (y[i,0].day<31):
b.append([y[i,0].day,y[i,0].hour,1])
c=pd.DataFrame(b)
e=c.groupby([0,1], as_index=False).aggregate(np.sum)
e=np.array(e)
e=e[1:108]
######################################################################
e10=np.array([datetime.datetime(2014,3,e[i,0],e[i,1]) for i in range(len(e))])
e10=pd.DataFrame(e10)
e=pd.DataFrame(e)
########################################################################
e3=e3.drop('key_0',1)
e4=pd.merge(e3,e, on=e3.index)
#########################################################################
e4 = e4.rename(columns={'2_x': 'Hidalgo', '2_y': 'NKM'})
ZZ = pd.melt(e4[['0_x','Hidalgo', 'NKM']], id_vars='0_x' )
ggplot(aes(x='0_x', y='value', colour='variable'), data=ZZ) + \
geom_line() + \
xlab("date") + \
ylab("nombre de tweet par heure") + \
scale_x_date(labels='%R %d %b')
#ggtitle("")
####################################################################
#scale_x_date(labels='%R %d %b')
#date_format("%b %Y"))
#mois année
#zip(index.minute
#zip(pd.DatetimeIndex(e3['0_x']).day,pd.DatetimeIndex(e3['0_x']).hour)
#DateFormatter('%b %d') # e.g., Jan 12
#'%H %d %Y'
#http://www.tutorialspoint.com/python/time_strptime.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment