Plotly Facet_col subplots titles - subplot

I read many posts similar to my questions but for some reasons they still don't work.
I'm working on the well known plotly database 'tips'. I want to show 2 subplots by 'sex' and then edit both subplots' titles. I start from this code:
df=px.data.tips()
names={'Femmine':'Plot1','Maschi':'Plot2'}
fig=px.box(df,x='day',y='tip',facet_col='sex')
Now I'd like to edit the default subtitles outcome('sex=Female', 'sex=Male') and replace them with
two names i stored in the dictioanry names. I tried this:
fig.for_each_annotation(lambda a: a.update(text=str(names.keys())))
fig
But the output gives me this:
Really, i know the solution is there but ...I simply can't find it. Any help?
Thanks

Based on the answer here: How to change titles (facet_col )in imshow (plotly)
df=px.data.tips()
names={'Femmine':'Plot1','Maschi':'Plot2'}
fig=px.box(df,x='day',y='tip',facet_col='sex')
for i, label in enumerate(names):
fig.layout.annotations[i]['text'] = label
fig.show()
Note that this works because your dictionary keys are the title you wish to update.
Otherwise, if you wanted the value instead (Plot1, Plot2), you should instead use:
for i, (key, value) in enumerate(names.items()):
fig.layout.annotations[i]['text'] = value

Related

how to select all cases containing a specific number in spss

can someone help me figure out how to select cases containing number 1, for example I coded nausea as side effect as 1 and was then noting it with other side effects as 1234 and now i wan to select all combinations with 1 but i cant figure out how. Or at least how to properly name what I am trying to achieve, since I am fairly new to spss so I can try to further search online.
I have tried variable = 1 and variable = 1 and neither worked and a few random commands that did not work either. I have put the variable as string and did not change anything either.
Once you change the variable into text you can use text search commands to find "1" within the text, like this for example:
compute nausea=(char.index(YourVariable,"1")>0).
char.index command searches for "1" in YourVariable - if it is there, it will output it's position in the text. If it isn't there, the output is 0. So nausea will get a value of 1 in all cases that contain "1" and will gat a value of 0 in all cases that don't.
NOTE - if you get as high as 10 in your numbers, this method will fail, as "10" contains "1". In order for any method to work here, you'd need to add a delimiter between the numbers when you record them, e.g. "1,3,8,17,22".

Exact match in dget function with an array as the criteria

Example Sheet I'm trying to get an exact match with an array in the criteria section of dget. Maybe there is another way to work around this, but I'm trying to give it a dynamic component in the array.
=dget('Micro Data'!$A$1:J,"PCR Score",{"Micro Type","Stage Type","Tank","ID#";"PCR PAL","Bright",F2,H2})
Sometimes all criteria matches multiple data points except the "Tank". However the tanks won't exactly match. Ex. All the data is the same in two data sets, except the tanks are CT1 and CT18. This then comes up with the #NUM! error. I'm trying to find if there is a way to get an exact match in the array data while still allowing it to reference the cell?
I know there is the option of making it "=XXX" making it a txt string, but this would take away the dynamic function. I would also loose the auto updating aspect when more data is added.
Thanks
Ryan, see my solution using a query, in Retain Log-GK, cell F2. I think it is just as dynamic as the dget, but perhaps not. It will need some error wrapping to avoid errors if no result found.
Formula is basically:
=query('Criteria Source'!A2:J5,
"select J where B = '"&D9&"' and C = '"&D10&"' and E = '"&D11&"' and D ='"& D2 & "' ",0)
I made all of the criteria dynamic, though obviously you can do it whatever way suits you best...
Let me know of any questions. I'll check back later...

How do i remove rows based on comma-separated list of values in a Power BI parameter in Power Query?

I have a list of data with a title column (among many other columns) and I have a Power BI parameter that has, for example, a value of "a,b,c". What I want to do is loop through the parameter's values and remove any rows that begin with those characters.
For example:
Title
a
b
c
d
Should become
Title
d
This comma separated list could have one value or it could have twenty. I know that I can turn the parameter into a list by using
parameterList = Text.Split(<parameter-name>,",")
but then I am unsure how to continue to use that to filter on. For one value I would just use
#"Filtered Rows" = Table.SelectRows(#"Table", each Text.StartsWith([key], <value-to-filter-on>))
but that only allows one value.
EDIT: I may have worded my original question poorly. The comma separated values in the parameterList can be any number of characters (e.g.: a,abcd,foo,bar) and I want to see if the value in [key] starts with that string of characters.
Try using List.Contains to check whether the starting character is in the parameter list.
each List.Contains(parameterList, Text.Start([key], 1)
Edit: Since you've changed the requirement, try this:
Table.SelectRows(
#"Table",
(C) => not List.AnyTrue(
List.Transform(
parameterList,
each Text.StartsWith(C[key], _)
)
)
)
For each row, this transforms the parameterList into a list of true/false values by checking if the current key starts with each text string in the list. If any are true, then List.AnyTrue returns true and we choose not to select that row.
Since you want to filter out all the values from the parameter, you can use something like:
= Table.SelectRows(#"Changed Type", each List.Contains(Parameter1,Text.Start([Title],1))=false)
Another way to do this would be to create a custom column in the table, which has the first character of title:
= Table.AddColumn(#"Changed Type", "FirstChar", each Text.Start([Title],1))
and then use this field in the filter step:
= Table.SelectRows(#"Added Custom", each List.Contains(Parameter1,[FirstChar])=false)
I tested this with a small sample set and it seems to be running fine. You can test both and see if it helps with the performance. If you are still facing performance issues, it would probably be easier if you can share the pbix file.
This seems to work fairly well:
= List.Select(Source[Title], each Text.Contains(Parameter1,Text.Start(_,1))=false)
Replace Source with the name of your table and Parameter1 with the name of your Parameter.

How to order a list of URLs in Google Spreadsheet in a cascade structure?

Let’s say I have a list of URLs like this:
https://moz.com/
https://moz.com/about
https://moz.com/about/contact
https://moz.com/about/jobs
https://moz.com/beginners-guide-to-seo
https://moz.com/blog
https://moz.com/blog/category/advanced-seo
https://moz.com/blog/advanced-seo/technical
https://moz.com/blog/advanced-seo/content
https://moz.com/blog/googles-walled-garden
https://moz.com/blog/local-search-ranking-factors-survey-results-2017
https://moz.com/explorer
https://moz.com/help
https://moz.com/help/guides
https://moz.com/help/guides/moz-pro-overview
And I wanted it to be displayd in different columns according to the depth of the structure. Like each part of the URL is a level in the sites hierarchy and I want to visualize the hierarchy as such:
https://moz.com/
https://moz.com/about
https://moz.com/about/contact
https://moz.com/about/jobs
https://moz.com/beginners-guide-to-seo
https://moz.com/blog
https://moz.com/blog/advanced-seo
https://moz.com/blog/advanced-seo/technical
https://moz.com/blog/advanced-seo/content
https://moz.com/blog/googles-walled-garden
https://moz.com/blog/local-search-ranking-factors-survey-results-2017
https://moz.com/explorer
https://moz.com/help
https://moz.com/help/guides
https://moz.com/help/guides/moz-pro-overview
How can I do this? I have already tried utilizing the split function for this but that does not work because it just splits the different parts of the URL into different columns and not the whole URL into the accordant column.
Thanks in advance :)
Suppose the range with links is A:A:
Put the formula =ArrayFormula(COUNTIF(REGEXMATCH(A2,$A$1:A1), true))*1 in B2 and drag it down
Put the formula =REPT(" ",B1)&A1 in C1 and drag it down.
Edit1
Here's the single formula to do the same:
=ARRAYFORMULA(rept(" ",MMULT(
--(REGEXMATCH(A1:A15,TRANSPOSE(OFFSET(A1:A15,1,)))),SIGN(A1:A15<>""))-1)&A1:A15)
Edit2
this is a brilliant solution thank you alot. However it seems I run
into problems with sites that include .html at the very end
(moz.com/about.html but moz.com/about/contact.html and so on). Any
ideas how to bypass that?
=ARRAYFORMULA(rept(" ",MMULT(--(REGEXMATCH(A1:A15,REGEXREPLACE(TRANSPOSE(OFFSET(A1:A15,1,)),"\.html$",""))),
SIGN(A1:A15<>""))-1)&A1:A15)
Notes:
the formula also replaces ".html" from the end of a string.

Looping in SPSS to work through the cases

I have a data set in SPSS containing a sequence of six variables from which I have to create a new variable which should contain the last value present in the sequence. Let's say the data look like this: (the second row contains all missing values but represents a case to which I'll merge some other variables later, so I need this too.)
DATA LIST /V1 TO V6 1-6.
BEGIN DATA
423451
73453
929
0257
END DATA.
Now if I wish to generate a variable named lastscr which should have values 1, ., 3, 9, 7. Can anyone help me on how should I do it in SPSS? I could not find any clue about it. Thank you in advance for any help.
This can easily be done with the DO REPEAT command:
DO REPEAT Var = V1 TO V6.
IF NOT(SYSMIS(Var)) lastscr = Var.
END REPEAT.

Resources