Creating a stacked Google Chart? - google-visualization

I am trying to create a stacked Google Chart. It's easy, but with the current data set I have i'm a bit confused. I need a stacked chart, but with some of the bars I don't need all columns. Some, I only need 2, 3 or sometimes just 1 column of data. For example, suppose I have:
data.addColumn('string', 'Topping');
data.addColumn('number', 'Nescafe Instant');
data.addColumn('number', 'Folgers Instant');
data.addColumn('number', 'Nescafe Beans');
data.addColumn('number', 'Folgers Beans');
data.addRows([
['2001', 321, 621, 816, 319],
['2002', 163, 231, 539, 594],
['2003', 125, 819, 123, 578],
['2004', 197, 536, 613, 298]
]);
I need this:
data.addColumn('string', 'Topping');
data.addColumn('number', 'Nescafe Instant');
data.addColumn('number', 'Folgers Instant');
data.addColumn('number', 'Nescafe Beans');
data.addColumn('number', 'Folgers Beans');
data.addRows([
['2001', 321, 621, 816, 319],
['2002', 163, 231, 539, 594],
['2003', 578],
['2004', 197, 536]
]);
With this current format, it does not work. Not only that, the third row (578) should refer to Folgers Beans and not Nescafe Instant. How can I fix these problems so that the graph displays and it also displays with the correct information?

I have figured out the answer. In order to solve this problem, you have to add undefined to the empty fields. For example:
data.addColumn('string', 'Topping');
data.addColumn('number', 'Nescafe Instant');
data.addColumn('number', 'Folgers Instant');
data.addColumn('number', 'Nescafe Beans');
data.addColumn('number', 'Folgers Beans');
data.addRows([
['2001', 321, 621, 816, 319],
['2002', 163, 231, 539, 594],
['2003', undefined, undefined, undefined, 578],
['2004', undefined, undefined, 197, 536]
]);

Related

Django Admin - Cannot delete certain users

When I use django admin to delete some users, it returns this error:
ERROR base handle_uncaught_exception Internal Server Error: /admin/auth/user/
Traceback (most recent call last):
File "/home/yuanyin/.virtualenvs/transcats/lib/python3.5/site-packages/django/core/handlers/base.py", line 235, in get_response
response = middleware_method(request, response)
File "/home/yuanyin/.virtualenvs/transcats/lib/python3.5/site-packages/htmlmin/middleware.py", line 44, in process_response
parser=parser)
File "/home/yuanyin/.virtualenvs/transcats/lib/python3.5/site-packages/htmlmin/minify.py", line 46, in html_minify
mini_soup = space_minify(soup, ignore_comments)
File "/home/yuanyin/.virtualenvs/transcats/lib/python3.5/site-packages/htmlmin/minify.py", line 69, in space_minify
space_minify(child, ignore_comments)
File "/home/yuanyin/.virtualenvs/transcats/lib/python3.5/site-packages/htmlmin/minify.py", line 69, in space_minify
space_minify(child, ignore_comments)
File "/home/yuanyin/.virtualenvs/transcats/lib/python3.5/site-packages/htmlmin/minify.py", line 69, in space_minify
space_minify(child, ignore_comments)
File "/home/yuanyin/.virtualenvs/transcats/lib/python3.5/site-packages/htmlmin/minify.py", line 69, in space_minify
space_minify(child, ignore_comments)
File "/home/yuanyin/.virtualenvs/transcats/lib/python3.5/site-packages/htmlmin/minify.py", line 69, in space_minify
space_minify(child, ignore_comments)
File "/home/yuanyin/.virtualenvs/transcats/lib/python3.5/site-packages/htmlmin/minify.py", line 69, in space_minify
space_minify(child, ignore_comments)
File "/home/yuanyin/.virtualenvs/transcats/lib/python3.5/site-packages/htmlmin/minify.py", line 69, in space_minify
space_minify(child, ignore_comments)
File "/home/yuanyin/.virtualenvs/transcats/lib/python3.5/site-packages/htmlmin/minify.py", line 69, in space_minify
space_minify(child, ignore_comments)
File "/home/yuanyin/.virtualenvs/transcats/lib/python3.5/site-packages/htmlmin/minify.py", line 101, in space_minify
soup.string.replace_with(new_string)
File "/home/yuanyin/.virtualenvs/transcats/lib/python3.5/site-packages/bs4/element.py", line 231, in replace_with
self.extract()
File "/home/yuanyin/.virtualenvs/transcats/lib/python3.5/site-packages/bs4/element.py", line 258, in extract
del self.parent.contents[self.parent.index(self)]
File "/home/yuanyin/.virtualenvs/transcats/lib/python3.5/site-packages/bs4/element.py", line 938, in index
for i, child in enumerate(self.contents):
File "/home/yuanyin/.virtualenvs/transcats/lib/python3.5/site-packages/gunicorn/workers/base.py", line 192, in handle_abort
sys.exit(1)
SystemExit: 1
But get this: it doesn't appear all the time. When I try to delete some users, it doesn't show up; it appears when I try to delete others. What's going on?
gunicorn might be aborting a very long request. Try setting --timeout to a higher value.

How to convert list of list to list of frozenset in original order in python

I have a list of lists and I want to convert to list of frozenset in original order. I've tried the code below but the output isn't in the original order.
data=[[118, 175, 181, 348, 353], [117, 175, 181, 371, 282, 297], [119, 166, 176, 54, 349]]
my code:
>>> transactionList=list()
>>> for rec in data:
transaction = frozenset(rec)
transactionList.append(transaction)
output i got is not in original order:
>>> transactionList
[frozenset([353, 348, 181, 118, 175]), frozenset([297, 175, 371, 181, 282, 117]), frozenset([176, 349, 54, 166, 119])]
my expected output in original order:
>>> transactionList
[frozenset([118, 175, 181, 348, 353]), frozenset([117, 175, 181, 371, 282, 297]),frozenset([119, 166, 176, 54, 349])]
frozensets, like sets, have no defined order. See Does Python have an ordered set? for ways to overcome this with custom classes.

Combochart with stacked bars

I'm currently using Google Visualisation library to (Google Charts) to visualize some of my data. I'm plotting a stacked bar graph with cumulative data, but I'd like to print an additional bar / line that shows the increase per day, rather than the total per day. I have read about Combo Charts but I can't seem to find a way to combine a stacked bar chart with a line chart.
Is this possible at all?
it's possible, is there more you can share? specifically a sample of the data?
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua New Guinea', 'Rwanda', 'Diff'],
['2004/05', 165, 938, 522, 998, 450, 614.6],
['2005/06', 135, 1120, 599, 1268, 288, 682],
['2006/07', 157, 1167, 587, 807, 397, 623],
['2007/08', 139, 1110, 615, 968, 215, 609.4],
['2008/09', 136, 691, 629, 1026, 366, 569.6]
]);
var options = {
title : 'Monthly Coffee Production by Country',
vAxis: {title: 'Cups'},
hAxis: {title: 'Month'},
seriesType: 'bars',
isStacked: true,
series: {5: {type: 'line'}}
};
var chart = new google.visualization.BarChart(document.getElementById("barchart_values"));
chart.draw(data, options);
}
<script src="https://www.google.com/jsapi"></script>
<div id="barchart_values" style="width: 900px; height: 300px;"></div>

Bokeh Line chart not plotting complete pandas dataframe

I'm not sure if this is an issue because charts are currently being updated in Bokeh but I can no longer plot a complete dataframe using Line charts from Bokeh in my Jupyter notebook. Using this example from the docs:
from collections import OrderedDict
import numpy as np
import pandas as pd
from bokeh.charts import Line
from bokeh.plotting import show, output_file
from bokeh.charts import Chart, Line
xyvalues = OrderedDict(
python=[2, 3, 7, 5, 26, 221, 44, 233, 254, 265, 266, 267, 120, 111],
pypy=[12, 33, 47, 15, 126, 121, 144, 233, 254, 225, 226, 267, 110, 130],
jython=[22, 43, 10, 25, 26, 101, 114, 203, 194, 215, 201, 227, 139, 160],
)
# any of the following commented are valid Line inputs
xyvalues = pd.DataFrame(xyvalues)
#xyvalues = xyvalues.values()
#xyvalues = np.array(xyvalues.values())
output_file("lines.html", title="line.py example")
chart = Line(xyvalues, title="Lines", ylabel='measures', legend=True)
show(chart)
I get: Incorrect dataframe plot which is clearly different to the example shown in the docs.
If I explicitly give the dataframe an index and pass all the columns like below then it gives the expected plot:
xyvalues = pd.DataFrame(xyvalues, index=range(14))
output_file("lines.html", title="line.py example")
chart = Line(xyvalues, y=['python', 'pypy', 'jython'],
title="Lines", ylabel='measures', legend=True)
show(chart)
My notebook specs:
You are using Jupyter notebook.
The version of the notebook server is 4.0.6 and is running on:
Python 2.7.11 |Anaconda 2.4.1 (64-bit)| (default, Dec 6 2015, 18:08:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
IPython 4.0.1 -- An enhanced Interactive Python.
Updating to 0.11.0dev4 through conda fixed the issue.
conda install -c bokeh/channel/dev bokeh

How do i get request and response count in scrapyd?

I am trying to get request and response count in scrapyd,while running multiple spider means 8 spider dynamically.I am try to get those count using python.
following counts:
enter code here{'downloader/request_bytes': 130427,
'downloader/request_count': 273,
'downloader/request_method_count/GET': 273,
'downloader/response_bytes': 2169984,
'downloader/response_count': 273,
'downloader/response_status_count/200': 271,
'downloader/response_status_count/404': 2,
'dupefilter/filtered': 416,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2015, 7, 21, 14, 21, 38, 13000),
'item_scraped_count': 119,
'log_count/DEBUG': 406,
'log_count/INFO': 44,
'offsite/domains': 9,
'offsite/filtered': 5865,
'request_depth_max': 14,
'response_received_count': 273,
'scheduler/dequeued': 273,
'scheduler/dequeued/memory': 273,
'scheduler/enqueued': 273,
'scheduler/enqueued/memory': 273,
'start_time': datetime.datetime(2015, 7, 21, 14, 16, 41, 144000)}
enter code here
Thanks,
Use the Stats Collection from Scrapy.
With this you can access the statistics dumped at the end to the console and if you write your own middleware you can combine the results of your 8 spiders together -- like in the example of the documentation.