I have an incanter time-series chart, which I can't seem to generate with the correct series labels on. My data looks like this:
__________________________
| :Time | :Count | :Name |
| 12344 | 0 | "A" |
| 12344 | 1 | "B" |
| 12344 | 2 | "C" |
| 12345 | 4 | "A" |
I have tried setting the series label to a small set of strings, but only the first value is displayed on the chart for the first series. My (incorrect sample) code to plot the chart looks like this:
(view (time-series-plot :Time :Count
:x-label "Date"
:y-label "Points"
:title "My Cool Graph"
:legend true
:group-by :Name
:series-label "A" "B" "C"
:data data-to-graph
:points true
))
Any pointers much appreciated.
Juse a guess but the line:
:series-label "A" "B" "C"
is getting converted into a map like:
{:series-label "A", "B" "C"}
which is still only passing a single item as :series-label.
perhaps you would like:
:series-label ["A" "B" "C"]
though I'm not sure if incanter takes multiple values for labels.
Related
I have a column in Google Sheets where each cell contains pre-defined logic. For example, something like the second column in this table:
| 1 | =A1*-1 |
| 2 | =B2*-1 |
| -3 | =C2*-1 |
Let's say later I want to add the same logic to each cell in column B. For example, make it such that it looks like:
| 1 | =MAX(A1*-1,0) |
| 2 | =MAX(B2*-1,0) |
| -3 | =MAX(C2*-1,0) |
What is the fastest way to do this, besides manually typing MAX(...,0) in each cell? Normal Sheets functions act on the value of the cell, not the logic, so I'm a bit lost.
To my knowledge there isn't a function that pipes in the logic from one cell to another ...
try:
=ARRAYFORMULA(IF(A1:A="",,IF(SIGN(A1:A)<0, A1:A*-1, 0)))
=ARRAYFORMULA(IF(A1:A="",,IF(SIGN(A1:A)>0, A1:A, 0)))
I have a jsonb structure on postgres named data where each row (there are around 3 million of them) looks like this:
[
{
"number": 100,
"key": "this-is-your-key",
"listr": "20 Purple block, THE-CITY, Columbia",
"realcode": "LA40",
"ainfo": {
"city": "THE-CITY",
"county": "Columbia",
"street": "20 Purple block",
"var_1": ""
},
"booleanval": true,
"min_address": "20 Purple block, THE-CITY, Columbia LA40"
},
.....
]
I would like to query the min_address field in the fastest possible way. In Django I tried to use:
APModel.objects.filter(data__0__min_address__icontains=search_term)
but this takes ages to complete (also, "THE-CITY" is in uppercase, so, I have to use icontains here. I tried dropping to rawsql like so:
cursor.execute("""\
SELECT * FROM "apmodel_ap_model"
WHERE ("apmodel_ap_model"."data"
#>> array['0', 'min_address'])
#> %s \
""",\
[json.dumps([{'min_address': search_term}])]
)
but this throws me strange errors like:
LINE 4: #> '[{"min_address": "some lane"}]'
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
I am wondering what is the fastest way I can query the field min_address by using rawsql cursors.
Late answer, probably it won't help OP anymore. Also I'm not at all an expert in Postgres/JSONB, so this might be a terrible idea.
Given this setup;
so49263641=# \d apmodel_ap_model;
Table "public.apmodel_ap_model"
Column | Type | Collation | Nullable | Default
--------+-------+-----------+----------+---------
data | jsonb | | |
so49263641=# select * from apmodel_ap_model ;
data
-------------------------------------------------------------------------------------------
[{"number": 1, "min_address": "Columbia"}, {"number": 2, "min_address": "colorado"}]
[{"number": 3, "min_address": " columbia "}, {"number": 4, "min_address": "California"}]
(2 rows)
The following query "expands" objects from data arrays to individual rows. Then it applies pattern matching to the min_address field.
so49263641=# SELECT element->'number' as number, element->'min_address' as min_address
FROM apmodel_ap_model ap, JSONB_ARRAY_ELEMENTS(ap.data) element
WHERE element->>'min_address' ILIKE '%col%';
number | min_address
--------+---------------
1 | "Columbia"
2 | "colorado"
3 | " columbia "
(3 rows)
However, I doubt it will perform well on large datasets as the min_address values are casted to text before pattern matching.
Edit: Some great advice here on indexing JSONB data for search https://stackoverflow.com/a/33028467/1284043
I'm not sure how to do this in a dataframe context
I have the table below here with text information
TEXT |
-------------------------------------------|
"Get some new #turbo #stacks today!" |
"Is it one or three? #phone" |
"Mayhaps it be three afterall..." |
"So many new issues with phone... #iphone" |
And I want to edit it down to where only the words with a '#' symbol are kept, like in the result below.
TEXT |
-----------------|
"#turbo #stacks" |
"#phone" |
"" |
"#iphone" |
In some cases, I'd also like to know if it's possible to eliminate the rows that are empty by checking for NaN as true or if you run a different kind of condition to get this result:
TEXT |
-----------------|
"#turbo #stacks" |
"#phone" |
"#iphone" |
Python 2.7 and pandas for this.
You could try using regex and extractall:
df.TEXT.str.extractall('(#\w+)').groupby(level=0)[0].apply(' '.join)
Output:
0 #turbo #stacks
1 #phone
3 #iphone
Name: 0, dtype: object
Is it possible to format both a row and column?
For instance I am doing a loop that uses the index to style rows different colors based on if it is even or odd but I also want to style a column that has percentages to use the :num_fmt => 9
Also why when I am presenting the number as something like 1.2 does that end up changing it to 120%, all I want is for that data to look like 1.2%
#people.each_with_index | person, index |
if index.odd?
sheet.add_row [person['name'], person['rate']]
else
sheet.add_row [person['name'],person['rate']], :style => even_row
end
end
(my even row style is set at the top of my code)
I figured this out, you need to do set your style using something like
percent = s.add_style(:num_fmt => 9)
even_row_percent = s.add_style(:bg_color => 'blue', :fg_color => 'white', :b => false, :format_code => 0%)
even_row = s.add_style(:bg_color => 'blue', :fg_color =>'white', :b => false)
then in your loop just use an each with index and then use a if statement like
if index.odd
sheet.add_row[
item[:value],
item[:value_percent]], :style => [nil, percent]
else
sheet.add_row[
item[:value],
item[:value]], :style => [even_row, even_row_percent]
end
I was wondering what would be the best way of specifying a default value when doing an outer-join in cascalog for field that could be null.
(def example-query
(<- [?id ?fname ?lname !days-active]
(users :> ?id ?fname ?lname)
(active :> ?fname ?lname !days-active))
In this example users and active would be previously defined queries and I'm just looking to correlate active user information (?fname ?lname !days-active) and regular user information (?id ?fname ?lname)
So when the join happened if there was no corresponding information for !days-active it would output 0 instead of nil
i.e.
392393 john smith 3
003030 jane doe 0
instead of
392393 john smith 3
003030 jane doe null
Updated Example
(<- [!!database-id ?feature !!user-clicks !!engaged-users ?application-id ?active-users]
(app-id-db-id-feature-clicks-engaged :> ?application-id !!database-id ?feature !!user-clicks !!engaged-users )
(user-info :> ?application-id ?feature ?active-users))]
example output would look something roughly like
4234 search null null 222 5000
3232 profile 500 400 331 6000
with the filtering that I'm interested I could change the fields that would be !!engaged-users and !!user-clicks to have 0 instead of null. Would using multiple Or predicates work?
I think what you want to do is add an or predicate:
(def example-query
(<- [?id ?fname ?lname !days-active]
(users :> ?id ?fname ?lname)
(active :> ?fname ?lname !days-active)
(or !days-active 0 :> ?active-days)))
That's not an outer join, by the way, it's just not filtering out null variables in the !days-active position.