I have normal python code to plot the graphs for csv data(data visualisation).But I need code in django and graphs should display on dashboard...
-- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1f9488c2-3cb1-4d24-8969-7b320f7ad907%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import calendar import numpy as np import time crimes=pd.read_csv(r"D:\python\Project\data.csv") crimes.head(2) crimes.describe() crimes.drop(['Unnamed: 0', 'Case Number','Block','IUCR', 'X Coordinate', 'Y Coordinate','Updated On', 'FBI Code', 'Beat','Ward','Community Area', 'Location','Latitude','Longitude','District'], inplace=True, axis=1) crimes.head(4) crimes=crimes[(crimes['Year']==2016)|(crimes['Year']==2015)] crimes.describe() f=plt.figure(1) sns.countplot(x='Year',data=crimes) plt.ylabel('No of Crimes') f.show() f1=plt.figure(2) crimes['Date'] = pd.to_datetime(crimes['Date'],format='%m/%d/%Y %I:%M:%S %p') crimes['Month']=(crimes['Date'].dt.month).apply(lambda x: calendar.month_abbr[x]) crimes.head(4) crimes['Month'] = pd.Categorical(crimes['Month'] , categories=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], ordered=True) months=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] crimes.groupby('Month')['ID'].count().plot(marker='o') plt.xticks(np.arange(12),months) plt.ylabel('No of Crimes') f1.show() f3=plt.figure(3) crimes["Weekday"] = crimes['Date'].dt.weekday_name crimes['Weekday'] = pd.Categorical(crimes['Weekday'],categories=['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday', 'Sunday'], ordered=True) crimes.head() crimes.groupby('Weekday')['ID'].count().plot(marker='o',label='Crimes') plt.ylabel('No of Crimes') f3.show() f4=plt.figure(4) sns.countplot(x='Primary Type',data=crimes,order=crimes['Primary Type'].value_counts().index) plt.xticks(rotation='vertical') plt.ylabel('No of Crimes') f4.show() f5=plt.figure(5) temp=crimes.groupby('Location Description')['ID'].count().sort_values(ascending=False) temp=temp[:10] temp temp.plot(kind='bar',color='green') plt.ylabel('No of Crimes') f5.show() f7=plt.figure(6) sns.countplot(x='Arrest',data=crimes) plt.ylabel('No of Crimes') f7.show() f9=plt.figure(7) sns.set(rc={'figure.figsize':(12,6)}) sns.countplot(x='Primary Type',hue='Arrest',data=crimes,order=crimes['Primary Type'].value_counts().index) plt.xticks(rotation='vertical') plt.ylabel('No of Crimes') f9.show() f10=plt.figure(8) arrest=crimes[crimes['Arrest']==True] arrest.info() arrest.groupby('Month')['ID'].count().plot(legend=True,label='Arrests',marker='o',figsize=(8,6)) crimes.groupby('Month')['ID'].count().plot(legend=True,label='Crimes',marker='o') plt.ylabel('No of Crimes') plt.xticks(np.arange(12),months) f10.show() f11=plt.figure(9) arrest.groupby('Month')['ID'].count() crimes.groupby('Month')['ID'].count() top_crime=crimes[(crimes['Primary Type']=='THEFT')|(crimes['Primary Type']=='BATTERY')|(crimes['Primary Type']=='CRIMINAL DAMAGE')|(crimes['Primary Type']=='NARCOTICS')|(crimes['Primary Type']=='ASSAULT')] temp=top_crime.pivot_table(values='ID', index='Month', columns='Year', aggfunc=np.size) sns.heatmap(temp) f11.show() f13=plt.figure(10) temp= top_crime.pivot_table(values='ID', index='Primary Type',columns=top_crime['Date'].dt.hour, aggfunc=np.size) sns.heatmap(temp) plt.xlabel('Hours of the day') plt.ylabel('Type of Crime') f13.show()