Count and Sort with Pandas

I think you need add reset_index, then parameter ascending=False to sort_values because sort return: FutureWarning: sort(columns=….) is deprecated, use sort_values(by=…..) .sort_values([‘count’], ascending=False) df = df[[‘STNAME’,’CTYNAME’]].groupby([‘STNAME’])[‘CTYNAME’] \ .count() \ .reset_index(name=”count”) \ .sort_values([‘count’], ascending=False) \ .head(5) Sample: df = pd.DataFrame({‘STNAME’:list(‘abscscbcdbcsscae’), ‘CTYNAME’:[4,5,6,5,6,2,3,4,5,6,4,5,4,3,6,5]}) print (df) CTYNAME STNAME 0 4 a 1 5 b 2 6 s 3 5 c … Read more

C# EPPlus OpenXML count rows

With a worksheet object called worksheet, worksheet.Dimension.Start.Row and worksheet.Dimension.End.Row should give you the information you need. worksheet.Dimension.Address will give you a string containing the worksheet dimensions in the traditional Excel range format (e.g. ‘A1:I5’ for rows 1-5, columns 1-9). There is a documentation file available. In many cases it might be just as quick to … Read more

How To Count Associated Entities Without Fetching Them In Entity Framework

Easy; just project onto a POCO (or anonymous) type: var q = from d in Model.Discussions select new DiscussionPresentation { Subject = d.Subject, MessageCount = d.Messages.Count(), }; When you look at the generated SQL, you’ll see that the Count() is done by the DB server. Note that this works in both EF 1 and EF … Read more

SQL Server Count is slow

Very close approximate (ignoring any in-flight transactions) would be: SELECT SUM(p.rows) FROM sys.partitions AS p INNER JOIN sys.tables AS t ON p.[object_id] = t.[object_id] INNER JOIN sys.schemas AS s ON s.[schema_id] = t.[schema_id] WHERE t.name = N’myTable’ AND s.name = N’dbo’ AND p.index_id IN (0,1); This will return much, much quicker than COUNT(*), and if … Read more

Django Count() in multiple annotations

I think Count(‘topics’, distinct=True) should do the right thing. That will use COUNT(DISTINCT topic.id) instead of COUNT(topic.id) to avoid duplicates. User.objects.filter( username_startswith=”ab”).annotate( posts=Count(‘post’, distinct=True)).annotate( topics=Count(‘topic’, distinct=True)).values_list( “username”,”posts”, “topics”)

How to count the number of occurrences of a character in an Oracle varchar value?

Here you go: select length(‘123-345-566’) – length(replace(‘123-345-566′,’-‘,null)) from dual; Technically, if the string you want to check contains only the character you want to count, the above query will return NULL; the following query will give the correct answer in all cases: select coalesce(length(‘123-345-566’) – length(replace(‘123-345-566′,’-‘,null)), length(‘123-345-566’), 0) from dual; The final 0 in coalesce … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)