 |
Reading a CSV file and plotting columns
Source code name: "io_read_csvdata.py"
Programming language: Python
Topic: File IO/CSV
DMelt Version 1. Last modified: 12/11/2015. License: Pro
https://datamelt.org/code/cache/io_read_csvdata_7850.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
from java.awt import Color,Font
from jhplot import *
file=SystemDir+fSep+"macros"+fSep+"examples"+fSep+"data"+fSep+"dcs_short.csv"
fdata = open(file,"r")
webdata=fdata.readlines()
print 'LENGTH :', len(webdata)
data=[]
for d in webdata:
line=d.split(",")
data.append(line)
c1=HPlot("Trips")
c1.visible()
c1.setAutoRange()
c1.setNameX("2011 Week")
c1.setNameY("Nr Trips")
# each histogram bin- one week
h=P1D("Status vs timestamp")
h.setFill(1)
h.setErrX(0)
h.setErrY(0)
h.setFillColor(Color.red)
h.setColor(Color.red)
for row in data:
timestamp=int(row[0])
time=row[1]
status=int(row[4])
h.add(timestamp,status)
c1.draw(h)
You see the box below because you did not login.