Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
29 views
Kernel: Python 2

IPython + gatherplot demo

1. Data Preprocess

Input data

Input file is Personal health care data

  • PHR.csv

Loading Data

We will use pandas for data structure. And we will use bokeh for the visualization.

%matplotlib inline import pandas as pd import numpy as np

Uploading to Gatherplot

This will upload to dropbox and then register link to the gatherplot.

import dropbox import re import time from firebase import firebase from IPython.display import IFrame def publish_gatherplot(p, dataname): filename = str(time.time())+'.csv' p.index.name = 'indexPandas' p.to_csv(filename) access_token = 'vwezSddRAD0AAAAAAAA0K2kAPqcpKnsShlfAPyIxSAYG0l2GxKfx5vtEkSyCeNOk' client = dropbox.client.DropboxClient(access_token) f = open(filename,'rb') response = client.put_file('./gatherplot/' + filename,f) print "uploaded:", response response = client.share('./gatherplot/' + filename, short_url=False) print 'Shared:', response url = response['url'] match = re.search(r'https://www\.dropbox\.com/s/(.+)\?dl=0', url) if match: # print match.group(1) download_url = 'https://dl.dropboxusercontent.com/s/' + match.group(1) print download_url aFirebase = firebase.FirebaseApplication('https://gatherplot-dev.firebaseio.com',None) new_csv = {'name':dataname, 'uploader':"google:110953151430048855242", 'uploaderName': "Deok Gun Park", 'url': download_url } result = aFirebase.post('/csv',new_csv) print result return 'https://gatherplot-dev.firebaseapp.com/#/load/' + result['name']
data = pd.read_csv('PHR.csv','rb') url = publish_gatherplot(data, "Test for Ipython integration") IFrame(url, 900,900)
uploaded: {u'icon': u'page_white', u'bytes': 82445, u'thumb_exists': False, u'rev': u'2515c00af1980', u'modified': u'Thu, 16 Apr 2015 18:01:03 +0000', u'shareable': False, u'client_mtime': u'Thu, 16 Apr 2015 18:01:03 +0000', u'path': u'/gatherplot/1429207261.49.csv', u'is_dir': False, u'size': u'80.5 KB', u'root': u'dropbox', u'mime_type': u'text/csv', u'revision': 151900} Shared: {u'url': u'https://www.dropbox.com/s/vtys5yflxql6kf5/1429207261.49.csv?dl=0', u'expires': u'Tue, 01 Jan 2030 00:00:00 +0000', u'visibility': u'PUBLIC'} https://dl.dropboxusercontent.com/s/vtys5yflxql6kf5/1429207261.49.csv {u'name': u'-Jn2O1o-iVpBvGCHuMOR'}
/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/pandas/io/parsers.py:639: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators; you can avoid this warning by specifying engine='python'. ParserWarning)

First check gatherplot with IFrame