create 4 different lines after grouping by numeric clumn

I have this dataframe.

t = pd.DataFrame({'A':[1,2,3,4], 'B':[40,50,60, 70], 'C':[400, 500, 600 ,700]}) 

and the series:

s = pd.Series([10000, 12000, 14000, 16000]) 

I merge them:

df = t.assign(target = s) 

Now, I want to groupby column ‘B’ by intervals of 10 and plot ‘A’ versus various ‘target’ values.

I want to have 4 different line plots.

If I do :

fig, ax = plt.subplots()  new_df = df.groupby(pd.cut(df.iloc[:, 1], np.arange(0, max(df.iloc[:, 1]) + 10, 10))).sum()  new_df.plot(x='A', y='target', ax=ax, legend=True, kind='line') 


I want to have 4 different lines. I am trying something like (it’s not right):

for col, b in df.groupby(pd.cut(df.iloc[:, 1], np.arange(0, max(df.iloc[:, 1]) + 10, 10))).sum():    ax = b.plot(ax=ax, kind='line', x = 'A', y = 'target', c=col, label=col) 

(this gives ‘not enough values to unpack (expected 2 got 1)’)

but I am not sure how to loop through this grouping.

Grouping SharePoint REST API results

I am building a customized events feed via REST query. I have a feed of all events in the calendar, filtered on date range and sorted, but I’d like to take it a step further and group the results by the day of the week. In my calendar list I have a DayOfWeek property that I am able to output via a groupBy function found on another thread:

function getListItems(url, listname, query, complete, failure) {     $  .ajax({         url: url + "/_api/web/lists/getbytitle('" + listname + "')/items" + query,         method: "GET",         headers: { "Accept": "application/json; odata=verbose" },         success: function (data) {             complete(data.d.results);          },         error: function (data) {             failure(data);         }     }); } function groupBy(items,propertyName) {     var result = [];     $  .each(items, function(index, item) {        if ($  .inArray(item[propertyName], result)==-1) {           result.push(item[propertyName]);        }     });     return result; }  getListItems('','Events','?select=Title,DayOfWeek',     function(items){            var daysOfWeek = groupBy(items,'DayOfWeek');        console.log(daysOfWeek);     },     function(error){        console.log(JSON.stringify(error));     } ); 

I am also able to populate a full events feed with the code below. What I am not sure how to accomplish is to now take the full results from my REST query and group the results by the daysOfWeek.

var a = new Date(); a = a.setDate(a.getDate() + 5); var d = new Date(a); var n = d.toISOString();     $  .ajax({ url: "/_api/web/lists/getbytitle('Events')/items?$  select=Title,EventDate,Location,CleanDate,DayOfWeek&$  top=10&$  orderby=EventDate&$  filter=EventDate le '" + n + "' and EventDate ge '"+new Date().toISOString()+"'", type: "GET", headers: {"Accept": "application/json;odata=verbose"}, cache:false,                 success: function(data){ console.log(data); var items = []; $  (data.d.results).each(function(){ items.push('<ul id="' + 'listUL' + '">' +  '<li id="' + 'listLI' + '">' + '<h1 class="dayHeader">' + this.DayOfWeek + this.EventDate + '</h1>' + '<p>' + this.Title + this.EventDate + this.Location + '</p>' + '</li>' +  '</ul>'); }); items.push("</div>"); $  ("#listResult").html(items.join(''))} });  

How could I combine these two approaches to achieve an events feed where items are grouped under the Day headings? Any tips would be greatly appreciated as I’m new to using REST.

Grouping Exposed Filters

I am working with the module Better Exposed Filters (BEF) within my view. I have about 12 exposed filters, some of theme are select lists and some are range sliders. Some filters thematically belong together which is why I try to visually group them under a headline. Unfortunately, this can’t be done using BEF.

I also tried Views Exposed Groups but this module can only be used instead of BEF, not together (I need BEF because of the slider funcionality). Besides I tried MEFIBS (More Exposed Filters in Blocks) which isn’t suitable for me too.

Does somebody know of another module that helps me to accomplish this problem?

PS: I am no coder so editing the exposed-form.tpl.php is the last option for me.

Thanks, Thomas

Sorting and grouping: What is the name of this type of problem? How do I implement the optimizations that i’ve thought of?

I have a facial recognition algorithm that compares two images A and B and returns the likelihood that they match.

I also have 50,000 images, and I would like to sort these images into groups.

Here’s the immediate way I thought of to do this:

  1. Start with image 0, compare it to all 49,999 images. Store the similarities in an array
  2. Move on to image 2, compare it to 49,998 images. Store the similarities in an array

At the end of it all I’m left with a verified_listof images that matched, and I can basically feed them into a network to combine them, ie if I have a verified_list like so:

[[1,2,3],[2,5,6],[8,9]] (verified_list is the same length as the number of images, so verified_list[1] contains references all the images that image_1 matches with)

then the network graph combines them into:

[[1,2,3,5,6], [8,9]

Indicating I have two groups.

Obviously this is a huge amount of processing, I think it equates to: nCr(50000,2), some huge number!

I would like to add some logic to improve this. I can think of what needs to be done but am not sure how to actually implement it.

Basically I just want to skip as many images as possible without reducing the overall quality of verified_list

Say I’ve arrived at image 4. I can loop through verified_list[1] to figure out if image_4 matches with image_1, but this seems like if I get to image 39,543, I would have to check all 39,542 verified_lists before figuring out if image_39543 has been matched to a group or not

I feel like I’m over complicating this issue quite a bit… Is there a name for this kind of problem? Is there a known best way to do this?

There’s also the issue where the recognition algorithm is not 100% accurate. Ie img_1 matches with img_2 and img_5, but img_5 only matches with img_1 and not img_2.

Grouping and displaying people by political demographics

I have a function that sorts and groups items inside an array and then adds a corresponding jsx element to the page.

I’ve already refactored it from 100 lines of code to 44, but I’m sure that its still unreadable pile of spaghetti code. I’ve tried filtering individuals and groups separately but that just bloats my code to some unbelievable extent so im looking for ways to reduce bloat and improve readability.

// array - array im sorting // ageStart - minimal age of person // ageEnd - minimum age of person // activity & time - specific to the jsx elements inside(dont really     play a role here) // function group(array, ageStart, ageEnd, activity, time = '') { // filtering by political views and age.     const polViewsLib = array.filter(item => item.polViews === 'Liberal'         && item.age >= ageStart         && item.age <= ageEnd)        //grouping items inside an array using  reduce(groups people     whose age difference is less than 5)        .reduce((acc, curr, ind, arr) => {         if (             !ind             || curr.age - arr[ind - 1].age > 5         )acc.push([]);         acc[acc.length - 1].push(curr);         return acc;         }, []);     const polViewsConservative = array.filter(item => item.polViews === 'Conservative'         && item.age >= ageStart         && item.age <= ageEnd).reduce((acc, curr, ind, arr) => {         if (             !ind             || curr.age - arr[ind - 1].age > 5         )acc.push([]);         acc[acc.length - 1].push(curr);         return acc;     }, []);   // returning data sorted by age and mapping them to corresponding jsx elements  return [polViewsLib, polViewsConservative].sort((a,b) => {  a[0].age - b[0].age;  }).map((item, index) => {         const res = item.length > 1 ? (             <PersonContainer                 key={item[index].id}                 data={item}                 visibility={activity}                 timePeriod={time}             />         )         : (             <Person                 key={}                 data={item[0]}                 visibility={activity}                 timePeriod={item}             />         );         return res;     });    } 

Typical item inside array that I process:

  {      id:151324,      name: 'John',      age: 45,      polViews: 'Liberal',    } 

Grouping field and display the result in chart

I am trying to display the data submitted through a webform in graphical manner using charts. I want to group the data by field.

For example , if there are n customers and they submit the order to purchase a product through a form. I want to draw a graph showing how much total money each customer spent on shopping respectively.

The problem is if a person order two times, I am not able to sum the total amount he spent on shopping. Though I selected group by field option with name, amount is displaying separately.

Enable grouping and ungrouping of rows in a locked worksheet (Google Sheets)

I need to share a spreadsheet with some locked cells, but it is necessary that the user can use the grouping and ungrouping functions of rows. Within the pooled range there are locked and unlocked cells.

The user must be able to view all the cells in the grouped range (cells locked and unlocked for editing).

In Excel I would use the following macro:

Private Sub Workbook_Open()    With Plan1      .Protect Password:="123", UserInterfaceOnly:=True      .EnableOutlining = True    End With  End Sub 

Can anyone tell me if there is equivalent function in Google Sheets?

enter image description here

How to print a taxonomy term’s field value alongside a Views grouping header?

In Drupal 8.4.4 I have a “Living Things” taxonomy vocabulary. One field on the terms in the vocabulary is “Most Common Name”, with machine name field_most_common_name. On my “Animalia” term its value would be “Animal”.

In Views, I have a “Taxon Media” view which lists media related to the taxonomy term. I display it in a block on the taxonomy term’s pages themselves (not on nodes). In the view I group media by another field, “Primary Taxon”, which is a reference to the term. It prints on the page as the grouping heading (e.g. “Animalia”).

How can I print the value of my “Most Common Name” field next to that title? i.e. “Animalia Animal”.

I have made a template, views-view-grouping--taxon-media.html.twig, cloned from the one in the Classy template, tested that works, then added the 4th line and tried a few other things such as content.field_most_common_name, but cannot get the field’s value to display:

<div class="view-grouping">   <div class="view-grouping-header">     {{ title }}     {{ field_most_common_name }}   </div>   <div class="view-grouping-content">{{ content }}</div> </div>