I have a dictionary whose key is string and value is float. How can I convert this dictionary to table with column name being the key and each value filled in?
Thank you in advance!
You need to enlist each dictionary entry before attempting flip as kdb expects a list of values for each column as opposed to a single value.
q)flip enlist each`Apple`Banana`Pear!1 2 3
Apple Banana Pear
-----------------
1 2 3
Related
I have two large spreadsheets with names in column A and values in column B. I need to compare spreadsheet 1 with spreadsheet 2 - matching the name and value exactly.
Would lookup array work or what would be best? Thank you
I have a table of attributes that I am trying to pivot off of and while the pivot makes sense, several key attribute values I am successfully pivoting off of are prefixed with numbers (for sorting purposes). These are important attributes (there are several like this) that we want to pivot and report on.
I found a similar question here: How to select a column containing dot in column name in kdb and am when I sanitize the dictionary .Q.id t prefixed the columns with a
When I ran type on the returned value it returned 99h so the pivot returns a dictionary.
I'm trying to leverage enlist(`1CODE)#t but to no avail as of yet.
Any thoughts or suggestions?
q) t
monthDate | 1CODE 2CODE 3CODE 4CODE
----------| ------------------------------------
2022.01.01| 18.0054 0.1537228 4.116678 9.332936
2022.02.01| 17.87151 0.1527959 3.866393 9.685012
2022.03.01| 17.739 0.1518747 3.646734 10.00515
...
You can't use colName#table on a keyed table (99h is a keyed table in this case, though yes a keyed table is also a dictionary). So you would have to unkey the table first using 0!
t:1!flip`monthDate`1CODE`2CODE!(2022.01.01 2022.02.01 2022.03.01;3?100.;3?10.);
q)((),`1CODE)#0!t
1CODE
--------
61.37452
52.94808
69.16099
q)((),`1CODE`2CODE)#0!t
1CODE 2CODE
------------------
61.37452 0.8388858
52.94808 1.959907
69.16099 3.75638
Tables in kdb are just lists of dictionaries. Type 99h can be both a keyed table and a dictionary. You can still use qsql if you've sanitised your table:
q)select a1CODE from .Q.id t
a1CODE
--------
18.0054
17.87151
17.739
Another option is to use xcol to rename your columns:
q)t:(`monthDate,`$1 rotate'string 1_cols t)xcol t
q)select CODE1 from t1
CODE1
--------
47.35547
75.21426
99.14374
I'm not sure what you mean by pivoting off of at the beginning, but an issue that sticks out to me is that the enlist function should use square brackets - rather than the round ones in in your post. So the code you want is:
enlist[`1CODE]#t
I would like to create a table with an amount attribute field but am unsure about how to make it have 2 decimals places only. Could someone show me an example.
Code I have :
create table name( FirstName CHAR(15), Amount ????)
You can use Numeric data type
NUMERIC(precision, scale)
http://www.postgresql.org/docs/9.3/static/datatype-numeric.html
i have this txt file:
"1","My Product 1","Vegetables","15.20"
"2","My Product 2","soda","9.52"
but when i import that with the wizard on Visual FoxPro 6 my result in the table is:
1 | My Product 1 | Vegetables | 15
2 | My Product 2 | Vegetables | 9
I've used SET DECIMALS TO 2 but it doesn't work. If I export again, the table in txt shows this:
"1","My Product 1","Vegetables","15"
"2","My Product 2","soda","9"
without decimals. So, how can I import decimals correctly to VFP with the wizard or with a sentence?
I don't know the format of your table, but here is something that will work for you. I am creating a temporary cursor as opposed to a permanent table, but a permanent table could do the same thing. You need to pre-define your columns in the same order and expected data type. In this case, the price I set as numeric with a length 10 max, but 2 decimal positions.
CREATE CURSOR C_Import;
( someID c(5),;
someProduct c(30),;
someOtherFld c(20),;
somePrice n(10,2))
Now, if you append the text file as CSV (comma separated values), VFP will recognize the decimal positions during the numeric import.
APPEND FROM YourTextFile.txt TYPE csv
If the the default decimal point is ',' you have to define before the append command: SET POINT TO '.'. Without that you'll get only integer value as price.
Remember after append to change it back to the original value.
Right Now, I have 8 tables that needs to transform into 1, and I need to add Rank to the Output Table.
By using, Amount Collected field from 1 of the 8 table.
Sample:
Table A: amount_assignment
Table B: amount_collected
OutputTable: Rank= 1 (based on the highest collected)
How can I place 1, 2, 3.... on the Output Table field Rank based on the computed 'amount_collected'?
you can try to use your inputdataflow-->tSortRow-->tMap. In tSortrow you can sort data based on amount column you need and then further in tMap you can put a sequence number to every row using Numeric.sequence("sequencename",1,1) in expression for rank_column