Data Visualization in
  Python/ Django
   By KENNETH EMEKA ODOH
     By KENNETH EMEKA ODO
Table of Contents
Introduction
Motivation
Method
Appendices
Conclusion
References
Introduction
 My background
 Requirements(
  Python, Django, Matplotlib, ajax ) and other
  third-party libraries.
 What this talk is about ( we will be restricted to
  python, matplotlib and django ).
 What this talk is not about ( we are not trying
  to re-implement Google analytics ).
 Source codes are available at (
  https://github.com/kenluck2001/PyCon2012_T
  alk ).
MOTIVATION
There is a need to represent the business
 analytic data in a graphical form. This is
 because a picture speaks more than a thousand
 words.




   Source: en.wikipedia.org
Where do we find
data?




   Source: en.wikipedia.org
Sources of Data

• CSV
• DATABASES
Steps for data gathering
 Identify the data source.
 Preprocessing of the data (
  removing nulls, wide characters )
  e.g. Google refine.
 Actual data processing ( perform
  some statistical analysis ).
 Present the clean data in
  descriptive format. i.e Data
  visualization
 See Appendix 1
Visual Representation of
            data
     Charts / Diagram format
     Texts format
       Tables
       Log files




Source: devk2.wordpress.com   Source: elementsdatabase.com
Categorization of data
 Real-time ( generating charts on
  real time. This can also include
  mechanism for refreshing the site to
  get the latest chart ).
  See Appendix 2
 Batch-based ( create charts from
  csv file. Example in my blog)
   See Appendix 2
Rules of Data Collection
 Keep data in the easiest process able form
  e.g database, csv
 Keep data collected with timestamp. The
  time that the data is collected or
  processed, for filtering .
 Gather data that are relevant to the
  business needs.
 Ensure that whenever the data grows so
  large. You have to prune some stale or old
  data that are no longer needed.
Where is the data
   visualization done?
 Server
  See Appendix from 2 - 6
 Client
  Examples of Javascript library
  DS.js ( http://d3js.org/ )
  gRaphael.js (
   http://g.raphaeljs.com/ )
Factors to Consider for
Choice of Visualization
 Where do we perform the
  visualization processing?
 Is it Server or Client?


It depends
 Security
 Scalability
Tools needed for data
analysis
 Csvkit
  (http://csvkit.readthedocs.org/en/latest/)
 networkx (graphs) (spatial analysis)
  (http://networkx.lanl.gov/)
 pySAL ( http://code.google.com/p/pysal/
  )
Appendices


Let the codes begin
Appendix 1
## This describes a scatter plot of solar radiation against the month.
This aim to describe the steps of data gathering.CSV file from data science
hackathon website. The source code is available in a folder named
“plotCode”
impoqv cuv
fqom
mavplovlib.backendu.backend_agg
impoqv FigtqeCanvauAgg au FigtqeCanvau
fqom mavplovlib.figtqe impoqv Figtqe

def
pqepaqeLiuv(monvh_mouv_common_liuv):
''' Pqepaqe vhe inptv foq pqoceuu by
qemoving all tnneceuuaqy valteu.
Replace "NA" sivh 0''
      otvptv_liuv = []
      foq x in monvh_mouv_common_liuv:
      if x != 'NA':
          otvptv_liuv.append(x)
Appendix 1                 contd.
def plovSolaqRadiavionAgainuvMonvh(filename):
    vqainRosReadeq =
cuv.qeadeq(open(filename, 'qb'), delimiveq=',')
    monvh_mouv_common_liuv = []
    Solaq_qadiavion_64_liuv = []
    foq qos in vqainRosReadeq:
         monvh_mouv_common = qos[3]
         Solaq_qadiavion_64 = qos[6]

monvh_mouv_common_liuv.append(monvh_mouv_common)

Solaq_qadiavion_64_liuv.append(Solaq_qadiavion_6
4)
     #conveqv all elemenvu in vhe liuv vo floav
shile ukipping vhe fiquv elemenv foq vhe 1uv
elemenv iu a deucqipvion of vhe field.
     monvh_mouv_common_liuv = [floav(i) foq i in
pqepaqeLiuv(monvh_mouv_common_liuv)[1:] ]
     Solaq_qadiavion_64_liuv = [floav(i) foq i in
pqepaqeLiuv(Solaq_qadiavion_64_liuv)[1:] ]
     fig=Figtqe()
     ax=fig.add_utbplov(111)
     vivle='Scavveq Diagqam of uolaq qadiavion
againuv monvh of vhe yeaq'
     ax.uev_xlabel('Mouv common monvh')
     ax.uev_ylabel('Solaq Radiavion')
     fig.utpvivle(vivle, fonvuize=14)
     vqy:
Data visualization by Kenneth Odoh
Appendix 2
Fqom vhe pqojecv   in   foldeq
named WebMonivoq

clauu LoadEvenv:

def fillMonivoqModel(uelf):
     foq monObj in
uelf.monivoqObjLiuv:
          mObj =
Monivoq(tql =
monObj[2], hvvpSvavtu =
monObj[0], qeuponueTime =
monObj[1], convenvSvavtu =
monObj[5])
Appendix 3
fqom django.hvvp impoqv HvvpReuponue
fqom mavplovlib.backendu.backend_agg
impoqv FigtqeCanvauAgg au FigtqeCanvaufqom
mavplovlib.figtqe
impoqv Figtqefqom YAAS.uvavu.modelu impoqv
RegiuveqedUueq, OnlineUueq, SvavBid #ucavveq diagqam of
ntmbeq of bidu made againuv ntmbeq of online tuequ
# seekly qepoqv
@uvaff_membeq_qertiqed
def seeklyScavveqOnlinUuqBid(qerteuv, seek_no):
     page_vivle='Weekly Scavveq Diagqam baued on Online
tueq vequeu Bid'
     seekno=seek_no
     fig=Figtqe()
     ax=fig.add_utbplov(111)
     yeaq=uvav.gevYeaq()
     onlUueqObj =
OnlineUueq.objecvu.filveq(seek=seekno).filveq(yeaq=yeaq)
     bidObj =
SvavBid.objecvu.filveq(seek=seekno).filveq(yeaq=yeaq)
     onlUueqliuv =
liuv(onlUueqObj.valteu_liuv('no_of_online_tueq', flav=Tqte))
     bidliuv =
liuv(bidObj.valteu_liuv('no_of_bidu', flav=Tqte))
      vivle='Scavveq Diagqam of ntmbeq of online Uueq
againuv ntmbeq of bidu (seek {0l){1l'.foqmav(seekno,yeaq)
     ax.uev_xlabel('Ntmbeq of online Uuequ')
     ax.uev_ylabel('Ntmbeq of Bidu')
     fig.utpvivle(vivle, fonvuize=14)
     vqy:
           ax.ucavveq(onlUueqliuv, bidliuv)
      excepv ValteEqqoq:
           pauu
Appendix 4
# Example of how database may be deleted to recover some space.
From folder named “YAAS”. Check task.py
@peqiodic_vauk(qtn_eveqy=cqonvab(h
otq=1, mintve=30, day_of_seek=0)
)
def deleveOldIvemuandBidu():
         htndeqedandvsenvydayu =
davevime.voday() -
davevime.vimedelva(dayu=120)
         myIvem =
Ivem.objecvu.filveq(end_dave__lve
=htndeqedandvsenvydayu ).deleve()

    myBid =
Bid.objecvu.filveq(end_dave__lve=
htndeqedandvsenvydayu
).deleve()#poptlave vhe
qegiuveqedtueq and onlinetueq model
av qegtlaq inveqvalu
Appendix 5

Check project in
YAAS/stats/

for more information on
statistical processing
Appendix 6
 # how to refresh the views in django. To keep the charts.
 updated. See WebMonitor project

 {% exvendu            "baue.hvml" %l

 {% block uive_sqappeq %l
 <div id="meuuageu">Updaving
 vableu ...</div>
 <ucqipv>
      ftncvion qefqeuh() {
             $.ajax({
                       tql:
 "/monivoq/",
                       utcceuu:
 ftncvion(dava) {
 $('#meuuageu').hvml(dava);
                       l
           l);

 uevInveqval("qefqeuh()", 10000
 0);
References
 Python documentation ( http://www.python.org/ )
 Django documentation (
  https://www.djangoproject.com/ )
 Stack overflow ( http://stackoverflow.com/ )
 Celery documentation
  (http://ask.github.com/celery/)


Pictures
 email logo ( http:// ambrosedesigns.co.uk )
 blog logo ( http:// sociolatte.com )
Thanks for listening
           Follow me using any of


                    @kenluck2001

                    kenluck2001@yahoo.com


                    http://kenluck2001.tumblr.com
                    /

                    https://github.com/kenluck200
                    1

More Related Content

PPTX
Visdjango presentation django_boston_oct_2014
PDF
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
PDF
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
PDF
Time Series Meetup: Virtual Edition | July 2020
PDF
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
PDF
Mozilla とブラウザゲーム
PPTX
Google apps script database abstraction exposed version
PDF
Building data flows with Celery and SQLAlchemy
Visdjango presentation django_boston_oct_2014
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Time Series Meetup: Virtual Edition | July 2020
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Mozilla とブラウザゲーム
Google apps script database abstraction exposed version
Building data flows with Celery and SQLAlchemy

What's hot (20)

PDF
JavaScript client API for Google Apps Script API primer
PDF
Reason and GraphQL
PDF
UIKonf App & Data Driven Design @swift.berlin
PDF
Gpars workshop
PDF
GPars howto - when to use which concurrency abstraction
PDF
Goal Based Data Production with Sim Simeonov
PDF
Web Scrapping with Python
PPTX
Data Types and Processing in ES6
PPTX
Python and Data Analysis
PPTX
Android architecture components
PDF
Scaling up data science applications
DOCX
library(sparkline)
PDF
GeoMesa on Apache Spark SQL with Anthony Fox
PDF
Talk about Testing at vienna.rb meetup #2 on Apr 12th, 2013
PDF
Taming the beast - how to tame React & GraphQL, one error at a time
PDF
How to Scrap Any Website's content using ScrapyTutorial of How to scrape (cra...
PDF
Web Crawling Modeling with Scrapy Models #TDC2014
PDF
Downloading the internet with Python + Scrapy
PPTX
Java 8 monads
PDF
Om nom nom nom
JavaScript client API for Google Apps Script API primer
Reason and GraphQL
UIKonf App & Data Driven Design @swift.berlin
Gpars workshop
GPars howto - when to use which concurrency abstraction
Goal Based Data Production with Sim Simeonov
Web Scrapping with Python
Data Types and Processing in ES6
Python and Data Analysis
Android architecture components
Scaling up data science applications
library(sparkline)
GeoMesa on Apache Spark SQL with Anthony Fox
Talk about Testing at vienna.rb meetup #2 on Apr 12th, 2013
Taming the beast - how to tame React & GraphQL, one error at a time
How to Scrap Any Website's content using ScrapyTutorial of How to scrape (cra...
Web Crawling Modeling with Scrapy Models #TDC2014
Downloading the internet with Python + Scrapy
Java 8 monads
Om nom nom nom
Ad

Similar to Data visualization by Kenneth Odoh (20)

PPTX
Data visualization in python/Django
PPTX
Python_Assignment_Review_Presentation.pptx
PPTX
PDF
S2-Programming_with_Data_Computational_Physics.pdf
PPTX
EDA.pptx
PDF
An Overview of Python for Data Analytics
PDF
Thinking in Functions: Functional Programming in Python
PDF
Class 12 Ip Whole Text Book Preeti Arora
PDF
Pycon Talk
PDF
Researh toolbox-data-analysis-with-python
PPTX
Researh toolbox - Data analysis with python
PDF
Wes McKinney - Python for Data Analysis-O'Reilly Media (2012).pdf
PDF
Fast and Scalable Python
PPTX
To understand the importance of Python libraries in data analysis.
PDF
(Ebook) Data Science with Python by coll.
PDF
Full-Stack Data Science: How to be a One-person Data Team
PPTX
Introduction to data analyticals123232.pptx
PDF
Pandas, Data Wrangling & Data Science
PDF
Data Science & AI Road Map by Python & Computer science tutor in Malaysia
KEY
Eat whatever you can with PyBabe
Data visualization in python/Django
Python_Assignment_Review_Presentation.pptx
S2-Programming_with_Data_Computational_Physics.pdf
EDA.pptx
An Overview of Python for Data Analytics
Thinking in Functions: Functional Programming in Python
Class 12 Ip Whole Text Book Preeti Arora
Pycon Talk
Researh toolbox-data-analysis-with-python
Researh toolbox - Data analysis with python
Wes McKinney - Python for Data Analysis-O'Reilly Media (2012).pdf
Fast and Scalable Python
To understand the importance of Python libraries in data analysis.
(Ebook) Data Science with Python by coll.
Full-Stack Data Science: How to be a One-person Data Team
Introduction to data analyticals123232.pptx
Pandas, Data Wrangling & Data Science
Data Science & AI Road Map by Python & Computer science tutor in Malaysia
Eat whatever you can with PyBabe
Ad

Recently uploaded (20)

PDF
August Patch Tuesday
PPTX
Chapter 5: Probability Theory and Statistics
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPT
What is a Computer? Input Devices /output devices
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
Getting Started with Data Integration: FME Form 101
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Unlock new opportunities with location data.pdf
PPTX
Modernising the Digital Integration Hub
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
CloudStack 4.21: First Look Webinar slides
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
STKI Israel Market Study 2025 version august
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
The various Industrial Revolutions .pptx
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Hindi spoken digit analysis for native and non-native speakers
August Patch Tuesday
Chapter 5: Probability Theory and Statistics
1 - Historical Antecedents, Social Consideration.pdf
What is a Computer? Input Devices /output devices
DP Operators-handbook-extract for the Mautical Institute
Getting Started with Data Integration: FME Form 101
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Unlock new opportunities with location data.pdf
Modernising the Digital Integration Hub
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
sustainability-14-14877-v2.pddhzftheheeeee
CloudStack 4.21: First Look Webinar slides
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
STKI Israel Market Study 2025 version august
Benefits of Physical activity for teenagers.pptx
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
The various Industrial Revolutions .pptx
A novel scalable deep ensemble learning framework for big data classification...
Hindi spoken digit analysis for native and non-native speakers

Data visualization by Kenneth Odoh

  • 1. Data Visualization in Python/ Django By KENNETH EMEKA ODOH By KENNETH EMEKA ODO
  • 3. Introduction  My background  Requirements( Python, Django, Matplotlib, ajax ) and other third-party libraries.  What this talk is about ( we will be restricted to python, matplotlib and django ).  What this talk is not about ( we are not trying to re-implement Google analytics ).  Source codes are available at ( https://github.com/kenluck2001/PyCon2012_T alk ).
  • 4. MOTIVATION There is a need to represent the business analytic data in a graphical form. This is because a picture speaks more than a thousand words. Source: en.wikipedia.org
  • 5. Where do we find data? Source: en.wikipedia.org
  • 6. Sources of Data • CSV • DATABASES
  • 7. Steps for data gathering  Identify the data source.  Preprocessing of the data ( removing nulls, wide characters ) e.g. Google refine.  Actual data processing ( perform some statistical analysis ).  Present the clean data in descriptive format. i.e Data visualization  See Appendix 1
  • 8. Visual Representation of data  Charts / Diagram format  Texts format  Tables  Log files Source: devk2.wordpress.com Source: elementsdatabase.com
  • 9. Categorization of data  Real-time ( generating charts on real time. This can also include mechanism for refreshing the site to get the latest chart ). See Appendix 2  Batch-based ( create charts from csv file. Example in my blog) See Appendix 2
  • 10. Rules of Data Collection  Keep data in the easiest process able form e.g database, csv  Keep data collected with timestamp. The time that the data is collected or processed, for filtering .  Gather data that are relevant to the business needs.  Ensure that whenever the data grows so large. You have to prune some stale or old data that are no longer needed.
  • 11. Where is the data visualization done?  Server See Appendix from 2 - 6  Client Examples of Javascript library DS.js ( http://d3js.org/ ) gRaphael.js ( http://g.raphaeljs.com/ )
  • 12. Factors to Consider for Choice of Visualization  Where do we perform the visualization processing?  Is it Server or Client? It depends  Security  Scalability
  • 13. Tools needed for data analysis  Csvkit (http://csvkit.readthedocs.org/en/latest/)  networkx (graphs) (spatial analysis) (http://networkx.lanl.gov/)  pySAL ( http://code.google.com/p/pysal/ )
  • 15. Appendix 1 ## This describes a scatter plot of solar radiation against the month. This aim to describe the steps of data gathering.CSV file from data science hackathon website. The source code is available in a folder named “plotCode” impoqv cuv fqom mavplovlib.backendu.backend_agg impoqv FigtqeCanvauAgg au FigtqeCanvau fqom mavplovlib.figtqe impoqv Figtqe def pqepaqeLiuv(monvh_mouv_common_liuv): ''' Pqepaqe vhe inptv foq pqoceuu by qemoving all tnneceuuaqy valteu. Replace "NA" sivh 0'' otvptv_liuv = [] foq x in monvh_mouv_common_liuv: if x != 'NA': otvptv_liuv.append(x)
  • 16. Appendix 1 contd. def plovSolaqRadiavionAgainuvMonvh(filename): vqainRosReadeq = cuv.qeadeq(open(filename, 'qb'), delimiveq=',') monvh_mouv_common_liuv = [] Solaq_qadiavion_64_liuv = [] foq qos in vqainRosReadeq: monvh_mouv_common = qos[3] Solaq_qadiavion_64 = qos[6] monvh_mouv_common_liuv.append(monvh_mouv_common) Solaq_qadiavion_64_liuv.append(Solaq_qadiavion_6 4) #conveqv all elemenvu in vhe liuv vo floav shile ukipping vhe fiquv elemenv foq vhe 1uv elemenv iu a deucqipvion of vhe field. monvh_mouv_common_liuv = [floav(i) foq i in pqepaqeLiuv(monvh_mouv_common_liuv)[1:] ] Solaq_qadiavion_64_liuv = [floav(i) foq i in pqepaqeLiuv(Solaq_qadiavion_64_liuv)[1:] ] fig=Figtqe() ax=fig.add_utbplov(111) vivle='Scavveq Diagqam of uolaq qadiavion againuv monvh of vhe yeaq' ax.uev_xlabel('Mouv common monvh') ax.uev_ylabel('Solaq Radiavion') fig.utpvivle(vivle, fonvuize=14) vqy:
  • 18. Appendix 2 Fqom vhe pqojecv in foldeq named WebMonivoq clauu LoadEvenv:  def fillMonivoqModel(uelf): foq monObj in uelf.monivoqObjLiuv: mObj = Monivoq(tql = monObj[2], hvvpSvavtu = monObj[0], qeuponueTime = monObj[1], convenvSvavtu = monObj[5])
  • 19. Appendix 3 fqom django.hvvp impoqv HvvpReuponue fqom mavplovlib.backendu.backend_agg impoqv FigtqeCanvauAgg au FigtqeCanvaufqom mavplovlib.figtqe impoqv Figtqefqom YAAS.uvavu.modelu impoqv RegiuveqedUueq, OnlineUueq, SvavBid #ucavveq diagqam of ntmbeq of bidu made againuv ntmbeq of online tuequ # seekly qepoqv @uvaff_membeq_qertiqed def seeklyScavveqOnlinUuqBid(qerteuv, seek_no): page_vivle='Weekly Scavveq Diagqam baued on Online tueq vequeu Bid' seekno=seek_no fig=Figtqe() ax=fig.add_utbplov(111) yeaq=uvav.gevYeaq() onlUueqObj = OnlineUueq.objecvu.filveq(seek=seekno).filveq(yeaq=yeaq) bidObj = SvavBid.objecvu.filveq(seek=seekno).filveq(yeaq=yeaq) onlUueqliuv = liuv(onlUueqObj.valteu_liuv('no_of_online_tueq', flav=Tqte)) bidliuv = liuv(bidObj.valteu_liuv('no_of_bidu', flav=Tqte)) vivle='Scavveq Diagqam of ntmbeq of online Uueq againuv ntmbeq of bidu (seek {0l){1l'.foqmav(seekno,yeaq) ax.uev_xlabel('Ntmbeq of online Uuequ') ax.uev_ylabel('Ntmbeq of Bidu') fig.utpvivle(vivle, fonvuize=14) vqy: ax.ucavveq(onlUueqliuv, bidliuv) excepv ValteEqqoq: pauu
  • 20. Appendix 4 # Example of how database may be deleted to recover some space. From folder named “YAAS”. Check task.py @peqiodic_vauk(qtn_eveqy=cqonvab(h otq=1, mintve=30, day_of_seek=0) ) def deleveOldIvemuandBidu(): htndeqedandvsenvydayu = davevime.voday() - davevime.vimedelva(dayu=120) myIvem = Ivem.objecvu.filveq(end_dave__lve =htndeqedandvsenvydayu ).deleve() myBid = Bid.objecvu.filveq(end_dave__lve= htndeqedandvsenvydayu ).deleve()#poptlave vhe qegiuveqedtueq and onlinetueq model av qegtlaq inveqvalu
  • 21. Appendix 5 Check project in YAAS/stats/ for more information on statistical processing
  • 22. Appendix 6 # how to refresh the views in django. To keep the charts. updated. See WebMonitor project {% exvendu "baue.hvml" %l {% block uive_sqappeq %l <div id="meuuageu">Updaving vableu ...</div> <ucqipv> ftncvion qefqeuh() { $.ajax({ tql: "/monivoq/", utcceuu: ftncvion(dava) { $('#meuuageu').hvml(dava); l l); uevInveqval("qefqeuh()", 10000 0);
  • 23. References  Python documentation ( http://www.python.org/ )  Django documentation ( https://www.djangoproject.com/ )  Stack overflow ( http://stackoverflow.com/ )  Celery documentation (http://ask.github.com/celery/) Pictures  email logo ( http:// ambrosedesigns.co.uk )  blog logo ( http:// sociolatte.com )
  • 24. Thanks for listening Follow me using any of @kenluck2001 kenluck2001@yahoo.com http://kenluck2001.tumblr.com / https://github.com/kenluck200 1