在DC.js github上,Lon Riesberg的股票市场选择策略被列为使用dc.js库的示例.
他能够对行进行颜色编码,如下图所示,我试图模仿它.

在这里查看我的代码:http://codepen.io/chriscruz/pen/myaWvR?edit = 101
特别是,我如何更改行的颜色,以便名称为"红色"的所有行都是红色,名称"蓝色"为蓝色,名称"白色"为白色.
使用Javascript:
items = [
{Id: "01", Name: "Red", Price: "1.00", Quantity: "1",TimeStamp:111},
{Id: "02", Name: "White", Price: "10.00", Quantity: "1",TimeStamp:222},
{Id: "04", Name: "Blue", Price: "9.50", Quantity: "10",TimeStamp:434},
{Id: "03", Name: "Red", Price: "9.00", Quantity: "2",TimeStamp:545},
{Id: "06", Name: "White", Price: "100.00", Quantity: "2",TimeStamp:676},
{Id: "05",Name: "Blue", Price: "1.20", Quantity: "2",TimeStamp:777}
];
var ndx = crossfilter(items);
var Dim = ndx.dimension(function (d) {return d.Name;})
dc.dataTable("#Table")
.width(250).height(800) …Run Code Online (Sandbox Code Playgroud) 我有兴趣使用python从文件中获取更多信息.
我知道使用os.stat(如下所示)会返回有关该文件的信息,但是我想从文件中获取其他属性,例如'Where from?'
os.stat(filename)
posix.stat_result(st_mode=33184, st_ino=131691855, st_dev=16777220L, st_nlink=1, st_uid=501, st_gid=20, st_size=174241, st_atime=1445046864, st_mtime=1445045836, st_ctime=1445045836)
Run Code Online (Sandbox Code Playgroud)
但是,这些并不是我感兴趣的属性.我有兴趣获得以下所有属性(特别是'Where from')
我怎样才能获得'Where from'字段?
我已经尝试过使用os.access了,但是这并没有返回我想要的内容,并且一直在搜索os上的文档,所以我不确定我还能尝试什么.
我想在执行时打印 python 脚本的每一行,以及在执行每一行时从控制台打印日志。
例如,对于这个脚本:
import time
print 'hello'
time.sleep(3)
print 'goodbye'
Run Code Online (Sandbox Code Playgroud)
我希望它在控制台中生成以下内容:
line 1: import time
line 2: print 'hello'
hello
line 3: time.sleep(3)
line 4: print 'goodbye'
goodbye
Run Code Online (Sandbox Code Playgroud)
请参阅下面的我的尝试
import subprocess as subp
python_string = """
import sys
import inspect
class SetTrace(object):
def __init__(self, func):
self.func = func
def __enter__(self):
sys.settrace(self.func)
return self
def __exit__(self, ext_type, exc_value, traceback):
sys.settrace(None)
def monitor(frame, event, arg):
if event == "line":
file_dict = dict(enumerate("{}".split("|")))
line_number = frame.f_lineno-25
if line_number > 0:
print "line …Run Code Online (Sandbox Code Playgroud) 如何将一个列表的每个项目附加到另一个列表的每个子列表?
a = [['a','b','c'],['d','e','f'],['g','h','i']]
b = [1,2,3]
Run Code Online (Sandbox Code Playgroud)
结果应该是:
[['a','b','c',1],['d','e','f',2],['g','h','i',3]]
Run Code Online (Sandbox Code Playgroud)
请记住,我想对一个非常大的列表执行此操作,因此效率和速度很重要。
我试过了:
for sublist,value in a,b:
sublist.append(value)
Run Code Online (Sandbox Code Playgroud)
它返回“ValueError:要解压的值太多”
也许 listindex 或 listiterator 可以工作,但不知道如何在这里应用
我已经创建了一个我想要传递给set.intersection()的集合列表
例如:
List_of_Sets = [{1,2,3},{3,4,5},{5,6,7}]
set.intersection(List_of_Sets)
Run Code Online (Sandbox Code Playgroud)
结果:
TypeError: descriptor 'intersection' requires a 'set' object but received a 'list'
Run Code Online (Sandbox Code Playgroud)
期望的输出:
{3,5}
Run Code Online (Sandbox Code Playgroud)
如何将列表中的每个集合作为单独的参数传递到set.intersection()?
如果子列表也存在于另一个列表中,您如何查找或仅保留列表的子列表?
lsta = [['a','b','c'],['c','d','e'],['e','f','g']]
lstb = [['a','b','c'],['d','d','e'],['e','f','g']]
Run Code Online (Sandbox Code Playgroud)
我想做类似set(lsta)和set(lstb)的事情
Desired_List = [['a','b','c'],['e','f','g']]
Run Code Online (Sandbox Code Playgroud)
我之所以想执行set之类的原因是因为它的速度,因为我在非常重要的大型列表中执行此操作。
另外,稍微不相关,如果我想从lsta中减去lstb以得到
Desired_List2 = [['d','d','e']]
Run Code Online (Sandbox Code Playgroud) 如何从数组中返回最低日期值和最高日期值?
例如,对于下面的数组,我想创建一个返回最低日期的函数,以及另一个返回最高日期的函数?
var data = [
{date: "2011-11-01T16:17:54Z", quantity: 2, total: 190, tip: 100, type: "tab"},
{date: "2011-11-14T16:20:19Z", quantity: 2, total: 190, tip: 100, type: "tab"},
{date: "2011-11-14T16:28:54Z", quantity: 1, total: 300, tip: 200, type: "visa"},
{date: "2011-11-14T16:30:43Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T16:48:46Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T16:53:41Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T16:54:06Z", quantity: 1, total: 100, tip: 0, type: "cash"},
{date: "2011-11-14T16:58:03Z", quantity: 2, …Run Code Online (Sandbox Code Playgroud) 我已经构建了一个带有firebase的应用程序,可以登录用户并获得他们的id,但我无法弄清楚如何将这个与用户提交字符串相结合.
请参阅此处的代码笔:http://codepen.io/chriscruz/pen/OPPeLg
HTML下面:
<html ng-app="fluttrApp">
<head>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<script src="https://cdn.firebase.com/js/client/2.0.2/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/0.9.0/angularfire.min.js"></script>
</head>
<body ng-controller="fluttrCtrl">
<button ng-click="auth.$authWithOAuthPopup('google')">Login with Google</button>
<li>Welcome, {{user.google.displayName }}</li>
<button ng-click="auth.$unauth()">Logout with Google</button>
<input ng-submit= "UpdateFirebaseWithString()" ng-model="string" ></input>
Run Code Online (Sandbox Code Playgroud)
Javascript下面:
<script>
var app = angular.module("fluttrApp", ["firebase"]);
app.factory("Auth", ["$firebaseAuth", function($firebaseAuth) {
var ref = new Firebase("https://crowdfluttr.firebaseio.com/");
return $firebaseAuth(ref);
}]);
app.controller("fluttrCtrl", ["$scope", "Auth", function($scope, Auth) {
$scope.auth = Auth;
$scope.user = $scope.auth.$getAuth();
$scope.UpdateFirebaseWithString = function () {
url = "https://crowdfluttr.firebaseio.com/ideas"
var ref = …Run Code Online (Sandbox Code Playgroud) 我正在使用datetime模块来生成当前日期.但是,当我在晚上7点之后运行时,当前日期变为明天的日期.
我不确定如何为以下模块设置时区
from datetime import *
print date.today()
Run Code Online (Sandbox Code Playgroud)
我已经阅读了文档,但还没有找到如何设置它.
我想在不更改格式的情况下更新文本框中的文本。换句话说,我想在更改文本时保留原始文本的原始格式
我可以使用以下内容更新文本,但在此过程中格式已完全更改。
from pptx import Presentation
prs = Presentation("C:\\original_powerpoint.pptx")
sh = prs.slides[0].shapes[0]
sh.text_frame.paragraphs[0].text = 'MY NEW TEXT'
prs.save("C:\\new_powerpoint.pptx")
Run Code Online (Sandbox Code Playgroud)
如何在保持原始格式的同时更新文本?
我还尝试了以下方法:
from pptx import Presentation
prs = Presentation("C:\\original_powerpoint.pptx")
sh = prs.slides[0].shapes[0]
p = sh.text_frame.paragraphs[0]
original_font = p.font
p.text = 'NEW TEXT'
p.font = original_font
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
Traceback (most recent call last):
File "C:\Codes\powerpoint_python_script.py", line 24, in <module>
p.font = original_font
AttributeError: can't set attribute
Run Code Online (Sandbox Code Playgroud) python ×7
javascript ×3
list ×3
date ×2
set ×2
sublist ×2
angularfire ×1
angularjs ×1
arrays ×1
crossfilter ×1
css ×1
datetime ×1
dc.js ×1
dictionary ×1
exec ×1
file ×1
firebase ×1
formatting ×1
frame ×1
function ×1
html ×1
inspect ×1
iteration ×1
iterator ×1
macos ×1
powerpoint ×1
python-pptx ×1
subprocess ×1