LINQ with Lambda expression – Left Join ,GroupBy ,Count

Necesito pasar esta expresion lambda para ser usada en c#, la uso para saber el número de chas por agentes

 SELECT     aa.UserId agent,     COUNT (c.Id) chatsPerAgent FROM     AvailableAgents aa LEFT OUTER JOIN Chat c ON aa.UserId = c.AgentId WHERE     aa.IsAvailable = 1 GROUP BY     aa.UserId  

y obtener algo asi donde la primera columna es el id del agente y la segunda el numero de chats que esta atendiendo

3fde3b78-815a-4c6a-b03c-a2b473ed12d2    3 74ac56eb-b8d6-44d3-914a-8af6386b00e6    0 a2d31e31-7052-445a-94d5-0af47f751c15    2 daeafdb2-52de-4126-a2eb-498346f3d1nh    0  

CSOM, GroupBy, specific ViewFields and system fields

From my SP library, I would need to retrieve a list of meetingID grouped by MeetingID. I tried several attempts with CAML but it didn’t work:

CamlQuery query = new CamlQuery();                     query.ViewXml = @"<View>                                           <Query>                                             <Where>                                                     <And>                                                                                         <And>                                                     <Eq>                                                         <FieldRef Name='FSObjType'/>                                                          <Value Type='Counter'>0</Value>                                                     </Eq>                                                     <Geq>                                                         <FieldRef Name='Modified'/>                                                         <Value IncludeTimeValue = 'TRUE' Type = 'DateTime'>2016-01-01T15:55:52Z</Value>                                                                </Geq>                                                   </And>                                                 <IsNotNull>                                                     <FieldRef Name='Title' />                                                                                               </IsNotNull>                                             </And>                                         </Where>                                                                                <GroupBy Collapse='True'>                                             <FieldRef Name='MeetingID' />                                         </GroupBy>                                                                                 <OrderBy>                                             <FieldRef Name='DocID' />                                                                                </OrderBy>                                     </Query>                                      <ViewFields>                                         <FieldRef Name='MeetingID'/>                                     </ViewFields>                                  </View>";                      ListItemCollection items = list.GetItems(query);                     cc.Load(items, o => o.Include(p => p["MeetingID"]));                     cc.ExecuteQuery(); 

Considering that the CAML is returning the MeetingID and plenty of system fields, I had to use the Include syntax. However,on my 1500 items in SP, none of them have been grouped (I should have only 50 unique MeetingID). Again probably related to the system fields which prevent the grouping to occur…

I also tried:

cc.Load(items, o => o.Include(p => p["MeetingID"]).GroupBy(g=>g["MeetingID"])); 

But this one return an error…

I also tried to see if a property similar to ViewFieldsOnly exist in CSOM but it doesn’t seem to be the case.

Your help will be appreciated

¿Como mostrar los datos en la vista desde una consulta groupBy() Laravel?

tengo una vista donde quisiera mostrar los datos en forma correcta tras hacer en el controlador la consulta groupBy().

En el controlador tengo:

 $  pormesYanios = Formulari::orderBy('created_at')->get()->groupBy(function($  item) {         return $  item->created_at->format('Y-m');     }); 

Y en la vista:

  <div id="accordion">                          @foreach($  pormesYanios as $  porfecha)                             <h2>TITULO</h2>                             <div style="max-height: 300px;">                                 <h4><span style="color:red;">FECHA:</span> <br> {{$  porfecha}}</h4>                             </div>                          @endforeach                     </div> 

Queda ordenado como quiero, pero me muestra los datos de esta forma: [{“id”:32,”sms_required”:0,”display”:10,”category”:0,”segment1″:16777215,”segment2″:511,”segment3″:7,”created_at”:”2018-03-09 12:14:15″,”updated_at”:”2018-05-07 13:02:28″,”title”:”HOJA DE MODIFICACI\u00d3N DATOS PERSONALES”,”description”:”–“}]

No se como hacer para mostrar solo los datos que me interesan y de forma correcta, como por ejemplo, dentro de una tabla.

Muchas gracias!

Nested GroupBy in c# Xamarin.forms

I need to create a var for nested groupby items

Data Set :
Item : grocery dop : 01/Jan/2019 Value : 2000 rs
Item : cell dop : 04/Mar/2019 Value : 10000 rs
Item : clothes dop : 05/Jan/2019 Value : 15000 rs
Item : Veggies dop : 06/Jan/2019 Value : 1500 rs
Item : grocery dop : 04/Jan/2019 Value : 1000 rs
Item : Veggies dop : 06/Jan/2019 Value : 200 rs
Item : tea dop : 04/Feb/2019 Value : 10 rs

I need the output like below

for loop (monthwise)
Jan Month in a grouped var based on Item Name
Item : clothes dop : 05/Jan/2019 Value : 15000 rs (Highest Value should come first)
Item : grocery dop : 01/Jan/2019 Value : 2000 rs (Same Item name )
Item : grocery dop : 04/Jan/2019 Value : 1000 rs (Same Item name )
Item : Veggies dop : 06/Jan/2019 Value : 1500 rs (Same Item name )
Feb
Item : tea dop : 04/Feb/2019 Value : 10 rs

Mar Item : cell dop : 04/Mar/2019 Value : 10000 rs

var groupListDop = expDetailsList.GroupBy(x => x.Dop.Month);
foreach (var month in groupListDop)
{
foreach (var day in month)
{
//I want here the Item name in a sorted Way } }

Pandas how to avoid apply in groupby nlargest n

Pandas apply is generally recommended not to be used. I have a situation here where I am interested if there are more efficient alternatives to the option of apply.

import numpy as np import pandas as pd  df = pd.DataFrame({'year': [1990,1990,1990,1992,1992,1992,1992,1993,1993,1993],                    'item': list('abcdefghij'),                   'value': [100,200,300,400,500,600,700,800,900,990]}) df 

I would like to get top 2 values for each year.

df.groupby('year')['value'].apply(lambda x: x.nlargest(2)).reset_index() 

Is there any alternative to this? Anything whether longer lines of codes or whatever!

calculate inventory turnover in python, taking difference using groupby?

i have a dataframe which contain inventory information. One column is product type (i.e A,B,C), one column is number of inventory for the product, one column record the data (i.e day 1, day 2, day 3). For example (see the table below), on day 1, we have 1 product A; on day 2, we have 3 product A and 2 product B; on day 3, we have 6 product B.

product | inventory | day    A    |    1      |  1     A    |    3      |  2    B    |    2      |  2    B    |    6      |  3 

I would like to calculate the product change for each day. The desired resulting table is shown below. The trick is that every day some products may be gone or some new product may come in. For example, on day 3, product A does not exist (in other words, all 3 product A on day 2 are gone on day 3). On day 2, new product B comes in as we do not have inventory for it on day 1. Remember, some product will disappear on certain day and come back later and then disappear again.

product | inventory_change | day    A    |    1             |  1     A    |    2             |  2    B    |    2             |  2    A    |    -3            |  3    B    |    4             |  3 

I am sure i can sue loop to go through each row to achieve it. I am wondering if there are any more efficient way to complete it without loop? I thinking use groupby, but still fail to come out about a way without using loop, especially given available product list could be different every day (i.e day1:A, day2 A,B; day3: B) Any idea or suggestions?

Pandas Groupby Conditional Aggregation

Let’s say you have a dataframe as follows:

data = pd.DataFrame({'Year': [2019]*5+[2020]*5,           'Month': [1,1,2,2,3]*2,           'Hour': [0,1,2,3,4]*2,           'Value': [0.2,0.3,0.2,0.1,0.4,0.3,0.2,0.5,0.1,0.2]}) 

Then, set “low” times to be hours between 1 and 3 (inclusive), and “high” times to be all other hours (in this case, hours 0 and 4). What I would like to do is get the average Value for the “low” and “high” times for each Year and Month.

For loops work, but they’re not ideal. I could also create a dummy variable (for instance, 0s and 1s) to signify the “low” and “high” times in the dataframe to groupby. However, it seems to me that there should be some way to use Pandas groupby([‘Year’, ‘Month’]).agg(…) to achieve the result in an efficient/optimal way. I haven’t had any luck thus far using groupby+agg, mainly because agg() uses only a series (not the remaining dataframe), so one can’t use a conditional within agg based on the Hour to calculate the average Value.

Any help is appreciated 🙂

How do we perform groupby operation on data fetched from a database

var grouped = from a in db.Logs                          group a by a.email into g  <!-- begin snippet: js hide: false console: true babel: false -->

I am using a table having email and login_time I need to group them based on email and from that i need to get the min login time of a particular email_id for datetime.today. I use min function to find the first login. I am using 24 hr format;