hierarchical

Hierarchical SQL question

守給你的承諾、 提交于 2019-11-28 12:51:28
I have a basic tree structure of entities. The tree can be a maximum of 5 nodes deep, but may be N nodes wide. I have mapped this relationship in table similar to what is shown below: myID | myDescription | myParentID I am starting out with a known object, which could translate to having a starting "myID". Now I want to get all the child nodes. Is there a way of getting all the child nodes in one statement? This needs to include the children of my children, and going on down the tree. I am using Oracle SQL. Thanks, Jay SELECT * FROM mytable START WITH myid = :id CONNECT BY myparentid = PRIOR

Hierarchical SQL question

淺唱寂寞╮ 提交于 2019-11-27 19:28:34
问题 I have a basic tree structure of entities. The tree can be a maximum of 5 nodes deep, but may be N nodes wide. I have mapped this relationship in table similar to what is shown below: myID | myDescription | myParentID I am starting out with a known object, which could translate to having a starting "myID". Now I want to get all the child nodes. Is there a way of getting all the child nodes in one statement? This needs to include the children of my children, and going on down the tree. I am

Hierarchical json from flat with parent ID

倖福魔咒の 提交于 2019-11-27 18:03:20
http://jsfiddle.net/eYgGK/ I stole this script from a different post: function convertToHierarchy() { var arry = [{ "Id": "1", "Name": "abc", "Parent": "", "attr": "abc" }, { "Id": "2", "Name": "abc", "Parent": "1", "attr": "abc" }, { "Id": "3", "Name": "abc", "Parent": "2", "attr": "abc" }, { "Id": "4", "Name": "abc", "Parent": "2", "attr": "abc" }]; var nodeObjects = createStructure(arry); for (var i = nodeObjects.length - 1; i >= 0; i--) { var currentNode = nodeObjects[i]; if (currentNode.value.Parent === "") { continue; } var parent = getParent(currentNode, nodeObjects); if (parent ===

How to get flat clustering corresponding to color clusters in the dendrogram created by scipy

一个人想着一个人 提交于 2019-11-27 12:48:54
Using the code posted here , I created a nice hierarchical clustering: Let's say the the dendrogram on the left was created by doing something like Y = sch.linkage(D, method='average') # D is a distance matrix cutoff = 0.5*max(Y[:,2]) Z = sch.dendrogram(Y, orientation='right', color_threshold=cutoff) Now how do I get the indices of the members of each of the colored clusters? To simplify this situation, ignore the clustering on the top, and focus only on the dendrogram on the left of the matrix. This information should be stored in the dendrogram Z stored variable. There is a function that

Selecting columns from pandas MultiIndex

久未见 提交于 2019-11-27 12:28:11
I have DataFrame with MultiIndex columns that looks like this: # sample data col = pd.MultiIndex.from_arrays([['one', 'one', 'one', 'two', 'two', 'two'], ['a', 'b', 'c', 'a', 'b', 'c']]) data = pd.DataFrame(np.random.randn(4, 6), columns=col) data What is the proper, simple way of selecting only specific columns (e.g. ['a', 'c'] , not a range) from the second level? Currently I am doing it like this: import itertools tuples = [i for i in itertools.product(['one', 'two'], ['a', 'c'])] new_index = pd.MultiIndex.from_tuples(tuples) print(new_index) data.reindex_axis(new_index, axis=1) It doesn't

pandas dataframe select columns in multiindex [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-11-27 10:29:42
This question already has an answer here: Selecting columns from pandas MultiIndex 7 answers I have the following pd.DataFrame: Name 0 1 ... Col A B A B ... 0 0.409511 -0.537108 -0.355529 0.212134 ... 1 -0.332276 -1.087013 0.083684 0.529002 ... 2 1.138159 -0.327212 0.570834 2.337718 ... It has MultiIndex columns with names=['Name', 'Col'] and hierarchical levels. The Name label goes from 0 to n, and for each label, there are two A and B columns. I would like to subselect all the A (or B ) columns of this DataFrame. There is a get_level_values method that you can use in conjunction with boolean

级联查询(Hierarchical Queries) 进阶应用:伪列LeveL

*爱你&永不变心* 提交于 2019-11-27 01:36:52
一、使用伪列Level显示表中节点的层次关系: Oracle9i对级联查询的支持不仅在于提供了像Start with...Connect by这样的子句供我们很方便地执行查询,而且还提供了一个伪列(Pseudocolumn): Level。这个伪列的作用是在递归查询的结果中用来表示节点在整个结构中所处的层次 下面我们来看看实际的例子: 还是上次那个employee表,现在我们要在上次的需求上面增加点小玩意:输出每个节点的层次值,看如下SQL: SQL> select level, id, emp_name, manager_id from employee start with id = 2 connect by prior id = manager_id order by id; LEVEL ID EMP_NAME MANAGER_ID ---------- ---------- -------------------- ---------- 1 2 mark 1 2 4 tom 2 2 5 paul 2 3 7 ben 4 SQL> 我们可以看到在LEVEL列,输出了1,2,2,3的值,这就是Oracle为我们提供的一个伪列。此伪列只能用在start with...connect by子句中,下面我们来看另一种方式是否可行: SQL> select level, p.*

Hierarchical json from flat with parent ID

Deadly 提交于 2019-11-26 18:00:27
问题 http://jsfiddle.net/eYgGK/ I stole this script from a different post: function convertToHierarchy() { var arry = [{ "Id": "1", "Name": "abc", "Parent": "", "attr": "abc" }, { "Id": "2", "Name": "abc", "Parent": "1", "attr": "abc" }, { "Id": "3", "Name": "abc", "Parent": "2", "attr": "abc" }, { "Id": "4", "Name": "abc", "Parent": "2", "attr": "abc" }]; var nodeObjects = createStructure(arry); for (var i = nodeObjects.length - 1; i >= 0; i--) { var currentNode = nodeObjects[i]; if (currentNode

pandas dataframe select columns in multiindex [duplicate]

坚强是说给别人听的谎言 提交于 2019-11-26 17:56:50
问题 This question already has an answer here: Selecting columns from pandas MultiIndex 7 answers I have the following pd.DataFrame: Name 0 1 ... Col A B A B ... 0 0.409511 -0.537108 -0.355529 0.212134 ... 1 -0.332276 -1.087013 0.083684 0.529002 ... 2 1.138159 -0.327212 0.570834 2.337718 ... It has MultiIndex columns with names=['Name', 'Col'] and hierarchical levels. The Name label goes from 0 to n, and for each label, there are two A and B columns. I would like to subselect all the A (or B )

How to get flat clustering corresponding to color clusters in the dendrogram created by scipy

点点圈 提交于 2019-11-26 16:08:01
问题 Using the code posted here, I created a nice hierarchical clustering: Let's say the the dendrogram on the left was created by doing something like Y = sch.linkage(D, method='average') # D is a distance matrix cutoff = 0.5*max(Y[:,2]) Z = sch.dendrogram(Y, orientation='right', color_threshold=cutoff) Now how do I get the indices of the members of each of the colored clusters? To simplify this situation, ignore the clustering on the top, and focus only on the dendrogram on the left of the