我有一个功能齐全的d3.js力导向图.尝试添加冲突检测,以便节点不重叠.但需要注意的是我的节点具有根据其d.inDegree和d.outDegree计算的变化半径.
node.attr("r", function(d) {
var weight = d.inDegree ? d.inDegree : 0 + d.outDegree ? d.outDegree : 0;
weight = weight > 20 ? 20 : (weight < 5 ? 5 : weight);
return weight;
});
Run Code Online (Sandbox Code Playgroud)
现在我试图在功能中使用这个变化半径进行碰撞检测
var padding = 1;
var radius = function(d) { var weight = d.inDegree ? d.inDegree : 0 + d.outDegree ? d.outDegree : 0;
weight = weight > 20 ? 20 : (weight < 5 ? 5 : weight);
return …
Run Code Online (Sandbox Code Playgroud) 我有一个熊猫数据框,如下所示:
id date value name
0 C1 2017-01-01 31 Company 1
1 C1 2017-01-02 35 Company 1
2 C1 2017-01-03 32 Company 1
3 C1 2017-01-06 36 Company 1
4 C1 2017-01-07 35 Company 1
5 C1 2017-01-08 34 Company 1
6 C1 2017-01-10 33 Company 1
7 C2 2017-01-01 225 Company 2
8 C2 2017-01-02 223 Company 2
9 C2 2017-01-03 223 Company 2
10 C2 2017-01-06 220 Company 2
11 C2 2017-01-07 222 Company 2
12 C2 2017-01-08 …
Run Code Online (Sandbox Code Playgroud) 我正在尝试将以下列表传递给sql查询
x = ['1000000000164774783','1000000000253252111']
Run Code Online (Sandbox Code Playgroud)
我正在使用sqlalchemy和pyodbc连接到sql:
import pandas as pd
from pandas import Series,DataFrame
import pyodbc
import sqlalchemy
cnx=sqlalchemy.create_engine("mssql+pyodbc://Omnius:MainBrain1@172.31.163.135:1433/Basis?driver=/opt/microsoft/sqlncli/lib64/libsqlncli-11.0.so.1790.0")
Run Code Online (Sandbox Code Playgroud)
我尝试使用各种字符串格式函数在sql查询中使用。下面是其中之一
xx = ', '.join(x)
sql = "select * from Pretty_Txns where Send_Customer in (%s)" % xx
df = pd.read_sql(sql,cnx)
Run Code Online (Sandbox Code Playgroud)
他们似乎都将其转换为数字格式
(1000000000164774783, 1000000000253252111) instead of ('1000000000164774783','1000000000253252111')
Run Code Online (Sandbox Code Playgroud)
因此查询失败,因为SQL 中Send_Customer的数据类型为varchar(50)
ProgrammingError: (pyodbc.ProgrammingError) ('42000', '[42000] [Microsoft][SQL Server Native Client 11.0]
[SQL Server]Error converting data type varchar to numeric. (8114) (SQLExecDirectW)')
[SQL: 'select * from Pretty_Txns where Send_Customer in (1000000000164774783, 1000000000253252111)']
Run Code Online (Sandbox Code Playgroud) 我有2个清单:
>>> phrases = ['emp_sal','emp_addr']
>>> cols = ['emp_sal_total','emp_sal_monthly','emp_addr_primary','emp_ssn','emp_phone']
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用列表推导并过滤掉cols,以便只选择cols中的那些值,其中包含短语emp_sal或emp_addr.
所以,输出应该是:
['emp_sal_total','emp_sal_monthly','emp_addr_primary']
Run Code Online (Sandbox Code Playgroud)
这只是复制场景的一个虚拟示例.实际例子具有COLS 180的奇数列的列表.
尝试下面的解决方案:
new_cols = [c for c in cols if p for p in phrases in c]
Run Code Online (Sandbox Code Playgroud)
它失败了:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'in <string>' requires string as left operand, not list
Run Code Online (Sandbox Code Playgroud)
以下方法产生一个空白列表:
>>> [c for c in cols if p in c for p in phrases]
[]
Run Code Online (Sandbox Code Playgroud)