I have two Tables in Google Sheet where i want to bring the values to one row with the corresponding quantity in second column from the Second Table.
First Table
+----------------------------+----------------------------+----------------------------+-----------------------------+----------------------------+---+---+----------------------------+
| A | B | C | D | E | F | G | H |
+----------------------------+----------------------------+----------------------------+-----------------------------+----------------------------+---+---+----------------------------+
| . | . | Paralite 1215 Ladies-BKB/4 | Paralite 1215 Ladies-BKB/5 | Paralite 1215 Ladies-BKB/6 | . | . | . |
| Paralite 1216 Ladies-BKR/1 | Paralite 1216 Ladies-BKR/2 | . | . | . | . | . | . |
| . | . | . | . | . | . | . | Paralite 1217 Ladies-BKR/9 |
+----------------------------+----------------------------+----------------------------+-----------------------------+----------------------------+---+---+----------------------------+
Second Table
+---+---+---+---+---+---+---+---+
| A | B | C | D | E | F | G | H |
+---+---+---+---+---+---+---+---+
| 0 | 0 | 8 | 6 | 8 | 0 | 0 | 0 |
| 4 | 8 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 |
+---+---+---+---+---+---+---+---+
Output I want
+----------------------------+---+
| A | B |
+----------------------------+---+
| Paralite 1215 Ladies-BKB/4 | 8 |
| Paralite 1215 Ladies-BKB/5 | 6 |
| Paralite 1215 Ladies-BKB/6 | 8 |
| Paralite 1216 Ladies-BKR/1 | 4 |
| Paralite 1216 Ladies-BKR/2 | 8 |
| Paralite 1217 Ladies-BKR/9 | 6 |
+----------------------------+---+
Google Sheet Link :
https://docs.google.com/spreadsheets/d/1c_vaT7-_cTLvPlcquK8Ax4aM6yYUQxBx15WS6yIAwa0/edit?usp=sharing
Try this:
=query(
{
flatten(A2:R7),
flatten(T2:AK7)
},
"where Col1 is not null",
0
)
If that does not cut it for you, please follow MattKing's advice and show your expected results in the sample spreadsheet. Clearly identify in the spreadsheet where the two source tables are and where your expected results are shown.
Use the following query for 2 tables like A1:H3 and A8:H10
=QUERY({FLATTEN(A1:H3),FLATTEN(A8:H10)},
" where Col1 <>'' and Col2 <>0 ",0)A1
Related
I have a tree structure like node(1)->node(2)->node(3). I have name as an property used to retrieve a node.
Given a node say node(3), i wanna retrieve node(1).
Query tried :
MATCH (p:Node)-[:HAS*]->(c:Node) WHERE c.name = "node 3" RETURN p LIMIT 5
But, not able to get node 1.
Your query will not only return "node 1", but it should at least include one path containing it. It's possible to filter the paths to only get the one traversing all the way to the root, however:
MATCH (c:Node {name: "node 3"})<-[:HAS*0..]-(p:Node)
// The root does not have any incoming relationship
WHERE NOT (p)<-[:HAS]-()
RETURN p
Note the use of the 0 length, which matches all cases, including the one where the start node is the root.
Fun fact: even if you have an index on Node:name, it won't be used (unless you're using Neo4j 3.1, where it seems to be fixed since 3.1 Beta2 at least) and you have to explicitly specify it.
MATCH (c:Node {name: "node 3"})<-[:HAS*0..]-(p:Node)
USING INDEX c:Node(name)
WHERE NOT (p)<-[:HAS]-()
RETURN p
Using PROFILE on the first query (with a numerical id property instead of name):
+-----------------------+----------------+------+---------+-------------------------+----------------------+
| Operator | Estimated Rows | Rows | DB Hits | Variables | Other |
+-----------------------+----------------+------+---------+-------------------------+----------------------+
| +ProduceResults | 0 | 1 | 0 | p | p |
| | +----------------+------+---------+-------------------------+----------------------+
| +AntiSemiApply | 0 | 1 | 0 | anon[23], c -- p | |
| |\ +----------------+------+---------+-------------------------+----------------------+
| | +Expand(All) | 1 | 0 | 3 | anon[58], anon[67] -- p | (p)<-[:HAS]-() |
| | | +----------------+------+---------+-------------------------+----------------------+
| | +Argument | 1 | 3 | 0 | p | |
| | +----------------+------+---------+-------------------------+----------------------+
| +Filter | 1 | 3 | 3 | anon[23], c, p | p:Node |
| | +----------------+------+---------+-------------------------+----------------------+
| +VarLengthExpand(All) | 1 | 3 | 5 | anon[23], p -- c | (c)<-[:HAS*]-(p) |
| | +----------------+------+---------+-------------------------+----------------------+
| +Filter | 1 | 1 | 3 | c | c.id == { AUTOINT0} |
| | +----------------+------+---------+-------------------------+----------------------+
| +NodeByLabelScan | 3 | 3 | 4 | c | :Node |
+-----------------------+----------------+------+---------+-------------------------+----------------------+
Total database accesses: 18
and on the second one:
+-----------------------+----------------+------+---------+-------------------------+------------------+
| Operator | Estimated Rows | Rows | DB Hits | Variables | Other |
+-----------------------+----------------+------+---------+-------------------------+------------------+
| +ProduceResults | 0 | 1 | 0 | p | p |
| | +----------------+------+---------+-------------------------+------------------+
| +AntiSemiApply | 0 | 1 | 0 | anon[23], c -- p | |
| |\ +----------------+------+---------+-------------------------+------------------+
| | +Expand(All) | 1 | 0 | 3 | anon[81], anon[90] -- p | (p)<-[:HAS]-() |
| | | +----------------+------+---------+-------------------------+------------------+
| | +Argument | 1 | 3 | 0 | p | |
| | +----------------+------+---------+-------------------------+------------------+
| +Filter | 1 | 3 | 3 | anon[23], c, p | p:Node |
| | +----------------+------+---------+-------------------------+------------------+
| +VarLengthExpand(All) | 1 | 3 | 5 | anon[23], p -- c | (c)<-[:HAS*]-(p) |
| | +----------------+------+---------+-------------------------+------------------+
| +NodeUniqueIndexSeek | 1 | 1 | 2 | c | :Node(id) |
+-----------------------+----------------+------+---------+-------------------------+------------------+
Total database accesses: 13
what should one specify when creating a graphlab recommender model such that the item that a user already own is not recommended to him again? Can this be done directly by specifying certain parameters or do I need to write a recommender from scratch.? data would look something like this
| user_id | item_id | othercolumns |
|:-----------|------------:|:------------:|
| 1 | 21 | This |
| 2 | 22 | column |
| 1 | 23 | will |
| 3 | 24 | hold |
| 2 | 25 | other |
| 1 | 26 | values |
Since item 21,23 and 26 are already owned by user 1 this item should not be recommended to him.
This behaviour is controlled by the exclude_known parameter of the recommender.recommend method (doc).
exclude_known : bool, optional
By default, all user-item interactions previously seen in the training
data, or in any new data provided using new_observation_data.., are
excluded from the recommendations. Passing in exclude_known = False
overrides this behavior.
Example
>>> import graphlab as gl
>>> sf = gl.SFrame({'user_id':[1,2,1,3,2,1], 'item_id':[21,22,23,24,25,26]})
>>> print sf
+---------+---------+
| item_id | user_id |
+---------+---------+
| 21 | 1 |
| 22 | 2 |
| 23 | 1 |
| 24 | 3 |
| 25 | 2 |
| 26 | 1 |
+---------+---------+
[6 rows x 2 columns]
>>> rec_model = gl.recommender.create(sf)
>>> # we recommend items not owned by user
>>> rec_wo_own_item = rec_model.recommend(sf['user_id'].unique())
>>> rec_wo_own_item.sort('user_id').print_rows(100)
+---------+---------+----------------+------+
| user_id | item_id | score | rank |
+---------+---------+----------------+------+
| 1 | 22 | 0.0 | 1 |
| 1 | 24 | 0.0 | 2 |
| 1 | 25 | 0.0 | 3 |
| 2 | 21 | 0.0 | 1 |
| 2 | 23 | 0.0 | 2 |
| 2 | 24 | 0.0 | 3 |
| 2 | 26 | 0.0 | 4 |
| 3 | 21 | 0.333333333333 | 1 |
| 3 | 23 | 0.333333333333 | 2 |
| 3 | 26 | 0.333333333333 | 3 |
| 3 | 22 | 0.166666666667 | 4 |
| 3 | 25 | 0.166666666667 | 5 |
+---------+---------+----------------+------+
[12 rows x 4 columns]
>>> # we recommend items owned by user
>>> rec_w_own_item = rec_model.recommend(sf['user_id'].unique(), exclude_known=False)
>>> rec_w_own_item.sort('user_id').print_rows(100)
+---------+---------+----------------+------+
| user_id | item_id | score | rank |
+---------+---------+----------------+------+
| 1 | 21 | 0.666666666667 | 1 |
| 1 | 23 | 0.666666666667 | 2 |
| 1 | 26 | 0.666666666667 | 3 |
| 1 | 22 | 0.0 | 4 |
| 1 | 24 | 0.0 | 5 |
| 1 | 25 | 0.0 | 6 |
| 2 | 26 | 0.0 | 6 |
| 2 | 24 | 0.0 | 5 |
| 2 | 23 | 0.0 | 4 |
| 2 | 21 | 0.0 | 3 |
| 2 | 25 | 0.5 | 2 |
| 2 | 22 | 0.5 | 1 |
| 3 | 24 | 0.0 | 6 |
| 3 | 25 | 0.166666666667 | 5 |
| 3 | 22 | 0.166666666667 | 4 |
| 3 | 26 | 0.333333333333 | 3 |
| 3 | 23 | 0.333333333333 | 2 |
| 3 | 21 | 0.333333333333 | 1 |
+---------+---------+----------------+------+
[18 rows x 4 columns]
>>> # we add recommended items not owned by user to the original SFrame
>>> rec = rec_wo_own_item.groupby('user_id', {'reco':gl.aggregate.CONCAT('item_id')})
>>> sf = sf.join(rec, 'user_id', 'left')
>>> print sf
+---------+---------+----------------------+
| item_id | user_id | reco |
+---------+---------+----------------------+
| 21 | 1 | [24, 25, 22] |
| 22 | 2 | [24, 26, 23, 21] |
| 23 | 1 | [24, 25, 22] |
| 24 | 3 | [21, 23, 26, 25, 22] |
| 25 | 2 | [24, 26, 23, 21] |
| 26 | 1 | [24, 25, 22] |
+---------+---------+----------------------+
[6 rows x 3 columns]
Can someone explain how these concept works?
I have 1 question. But I don't know have any ideas on constructing the truth table.
f(A,B,C) = AB + A’C
The answer given was ABC + ABC' + A'BC + A'B'C
And i have no idea how it get there. :-(
1. Create a column for each of the inputs, each intermediate functions, and the final function:
A B C | AB | A' | A'C | AB + A'C
--------------------------------
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
2. Enumerate all input possibilities, and start filling in the intermediate function values and then the final function value:
A B C | AB | A' | A'C | AB + A'C
--------------------------------
0 0 0 | 0 | 1 | 0 | 0
0 0 1 | | | |
0 1 0 | | | |
0 1 1 | | | |
1 0 0 | | | |
1 0 1 | | | |
1 1 0 | | | |
1 1 1 | | | |
3. Now, you finish the truth table.
Update per OP's edit of question:
The "answer given" can be reduced as follows using Boolean Algebra:
ABC + ABC' + A'BC + A'B'C
AB(C + C') + A'C(B + B')
AB + A'C
...which is the same as the given f(A,B,C). Not sure why ABC + ABC' + A'BC + A'B'C would be considered to be the "answer," but this does show equivalence between the two formulae.
Is it possible to do union of two queries (from the same entity) in core data? In SQL speak, if entity is called t, then consider that T has following data:
+------+------+------+
| x | y | z |
+------+------+------+
| 1 | 11 | 2 |
| 1 | 12 | 3 |
| 2 | 11 | 1 |
| 3 | 12 | 3 |
Then I am trying to run the following query (using core data - not SQLite)
select x, y, sum(z)
from t
group by 1, 2
union
select x, 1 as y, sum(z)
from t
group by 1, 2
order by x, y, 1
;
+------+------+--------+
| x | y | sum(z) |
+------+------+--------+
| 1 | 1 | 5 |
| 1 | 11 | 2 |
| 1 | 12 | 3 |
| 2 | 1 | 1 |
| 2 | 11 | 1 |
| 3 | 1 | 3 |
| 3 | 12 | 3 |
+------+------+--------+
7 rows in set (0.00 sec)
Is it possible?
Thanks!
I use the following code to copy dbf/mdx files from one folder to another:
procedure TfrmMain.MyCopyFile(S1, S2: string);
begin
if not FileExists(S2) then
CopyFile(PCHAR(S1), PCHAR(S2), true)
else
if Application.MessageBox(PCHAR('Overwrite existing file ' + S2 + '?'), 'File exists in folder',MB_YESNO + MB_DEFBUTTON1) = IDYES
then CopyFile(PCHAR(S1), PCHAR(S2), false)
end;
The code works fine when table name stays the same.
If I change the name of the table:
MyCopyFile(CurPath + '\orders.dbf', NewPath + '\ordly.dbf');
MyCopyFile(CurPath + '\orders.mdx', NewPath + '\ordly.mdx');
When I try to open ordly.dbf I get an error message:
Corrupt table/index header.
File: C:\DATA\2011\ORDLY.MDX
the problem is due to the mdx format stores inside the name of the data file associated (table name). because that when you rename a mdxfile the index still points to the old name of data file.
check this link to see the structure of the mdx file.
The Structure of Multiple Index files (*.mdx)
0 | Version number *1| ^
|-----------------------| |
1 | Date of creation | |
2 | YYMMDD | |
3 | | |
|-----------------------| |
4 | Data file name | File
5 | (no extension) | Header
: : |
: : |
19 | | |
|-----------------------| |
20 | Block size | |
| | |
|-----------------------| |
22 | Block size adder N | |
| | |
|-----------------------| |
24 | Production index flag | |
|-----------------------| |
25 | No. of entries in tag | | *2
|-----------------------| |
26 | Length of tag | | *3
|-----------------------| |
27 | (Reserved) | |
|-----------------------| |
28 | No.of tags in use | |
| | |
|-----------------------| |
30 | (Reserved) | |
| | |
|-----------------------| |
32 | No.of pages in tagfile| |
| | |
| | |
35 | | |
|-----------------------| |
36 | Pointer to first free | |
| page | |
| | |
39 | | |
|-----------------------| |
40 | No.of block available | |
| | |
| | |
43 | | |
|-----------------------| |
44 | Date of last update | |
| YYMMDD | |
46 | | |
|-----------------------| |
47 | (Reserved) | |
|-----------------------| |
48 | (Garbage) | |
: : |
: : |
| | | ___|=======================|
543| | _V___ / 0 | Tag header page no. |
|-----------------------| | / | |
544| Tag table entries | Tag / | |
| | Table | 3 | |
:.......................: | | |-----------------------| Tag
: : | | 4 | Tag name | table
:.......................: | | : :
: : | / : :
: : | / | |
:.......................:__|_/ 14 | |
: : | |-----------------------|
: : | 15 | Key format *4 |
: : | |-----------------------|
:.......................:__|_ 16 | Forward tag thread (<)|
: : | \ |-----------------------|
: : | \ 17 | Forward tag thread (>)|
: : | \ |-----------------------|
: : | | 18 | Backward tag thread *5|
| | | | |-----------------------|
| | | | 19 | (Reserved) |
M*N| |__V__ | |-----------------------|
|=======================| ^ | 20 | Key type *6 |
0| Pointer to root page | | | |-----------------------|
| | | | 21 | (Reserved) |
| | | | : :
3| | | | : :
|-----------------------| | | 31 | |
4| File size in pages | Tag | |-----------------------|
| | header| 32 | (Garbage) |
| | | | : :
7| | | | | |
|-----------------------| | \ N | |
8| Key format *7 | | \____|=======================|
|-----------------------| |
9| Key type *8 | |
|-----------------------| |
10| (Reserved) | |
| | |
|-----------------------| |
12| Index key length *9 | |
| | |
|-----------------------| |
14| Max.no.of keys/page | |
| | |
|-----------------------| |
16| Secondary key type *10| |
| | |
|-----------------------| |
18| Index key item length | |
| | |
|-----------------------| |
20| (Reserved) | |
| | |
| | |
|-----------------------| |
23| Unique flag | |
|-----------------------| |
| | |
: : |
: :__V__
N*M|=======================|