count

Count() returning 1 with comma separated string with explode

眉间皱痕 提交于 2020-02-25 07:23:47
问题 I have a field that stores tags comma seperated. I'm trying to count the number of items listed. Let's say I've already pulled the data from the DB, and the $tags variable has the following info: $tags = "Videos,Magazines,Store"; // First separate tags by commas, put into into array $tagArray = explode(",",$tags); // Count how many items are in the array $arrayCount = count($tagArray); That always returns "1", regardless if there's an item in the array or not. the $tags variable can have any

How to count different elements in list of lists?

烂漫一生 提交于 2020-02-25 07:11:31
问题 The example is... >>>list1 = [[1,2,3],[1,2,3],[1,2,2],[1,2,2]] >>>how_many_different_lists(list1) >>>2 #They are [1,2,3] and [1,2,2] How can I make the how_many_different_lists function? (sorry for the bad English) 回答1: Here`s working code: from copy import deepcopy def how_much_dif_l(arg): arg_list=deepcopy(arg) i=0 length=len(arg_list) while i<length: a = arg_list[i] if arg_list.count(a)>1: length-=1 arg_list.remove(a) else: i+=1 return len(arg_list) list1= [[1,2,3],[1,2,3],[1,2,2],[1,2,2]]

Get unique values and their occurrence out of one dataframe into a new dataframe using Pandas DataFrame

江枫思渺然 提交于 2020-02-24 14:10:34
问题 I want to turn my dataframe with non-distinct values underneath each column header into a dataframe with distinct values underneath each column header with next to it their occurrence in their particular column. An example: My initial dataframe is visible underneath: A B C D 0 CEN T2 56 2 DECEN T2 45 3 ONBEK T2 84 NaN CEN T1 59 3 NaN T1 87 NaN NaN T2 NaN 0 NaN NaN 98 NaN CEN NaN 23 NaN CEN T1 65 where A, B, C and D are the column headers with each 9 values underneath it (blanks included). My

mySQL count occurrences with JOIN

五迷三道 提交于 2020-02-23 08:08:20
问题 I have a tagging system for my events system I would like to create a 'tag cloud'. I have Events, which can have multiple 'categories'. Here's the table structure: **Event_Categories** (Stores Tags / Categories) | id | name | +-----------------+ + 1 | sport | + 2 | charity | + 3 | other_tag | **Events_Categories** (Linking Table) | event_id | event_category_id | +-------------------------------+ + 1 | 1 | + 2 | 2 | + 3 | 1 | + 3 | 2 | Summary: Event ID 1 -> Sport Event ID 2 -> Charity Event

NSMutableArray does not add objects [duplicate]

天大地大妈咪最大 提交于 2020-02-22 06:48:06
问题 This question already has answers here : NSMutableArray addObject not working (3 answers) Cannot add object to an NSMutableArray array (2 answers) Closed 6 years ago . I think, I am doing a pretty basic mistake, but I am using an NSMutableArray and this somehow doesn't add the object, I'm sending it its way. I have a property (and synthesize) @property (nonatomic, strong) NSMutableArray *kpiStorage; and then: ExampleObject *obj1 = [[ExampleObject alloc] init]; [kpiStorage addObject:obj1];

NSMutableArray does not add objects [duplicate]

点点圈 提交于 2020-02-22 06:45:53
问题 This question already has answers here : NSMutableArray addObject not working (3 answers) Cannot add object to an NSMutableArray array (2 answers) Closed 6 years ago . I think, I am doing a pretty basic mistake, but I am using an NSMutableArray and this somehow doesn't add the object, I'm sending it its way. I have a property (and synthesize) @property (nonatomic, strong) NSMutableArray *kpiStorage; and then: ExampleObject *obj1 = [[ExampleObject alloc] init]; [kpiStorage addObject:obj1];

Using “$count” Within an “addField” Operation in MongoDB Aggregation

六眼飞鱼酱① 提交于 2020-02-19 05:47:11
问题 I am trying to find the correct combination of aggregation operators to add a field titled "totalCount" to my mongoDB view. This will get me the count at this particular stage of the aggregation pipeline and output this as the result of a count on each of the documents: { $count: "count" } But I then end up with one document with this result, rather than what I'm trying to accomplish, which is to make this value print out as an addedField that is a field/value on all of the documents, or even

How to get the COUNT(*) based on two conditions [duplicate]

孤街醉人 提交于 2020-02-16 09:00:33
问题 This question already has answers here : mysql count occurrences of special character in a field (2 answers) Closed last month . I am having trouble in getting the count(*) based on the condition. Following is my data id | user_id | key | value ---+---------+------------+------------------------- 1 | 3434 | first_name | Brandon 2 | 3434 | last_name | Johnson,Brett,Jack 3 | 3434 | street_add | 123 main 4 | 3434 | city | ocean beach 5 | 3434 | state | Texas My query is SELECT COUNT(*) from

How to get the COUNT(*) based on two conditions [duplicate]

本秂侑毒 提交于 2020-02-16 09:00:02
问题 This question already has answers here : mysql count occurrences of special character in a field (2 answers) Closed last month . I am having trouble in getting the count(*) based on the condition. Following is my data id | user_id | key | value ---+---------+------------+------------------------- 1 | 3434 | first_name | Brandon 2 | 3434 | last_name | Johnson,Brett,Jack 3 | 3434 | street_add | 123 main 4 | 3434 | city | ocean beach 5 | 3434 | state | Texas My query is SELECT COUNT(*) from

How do we count rows using older versions of Hibernate (~2009)?

狂风中的少年 提交于 2020-02-08 21:42:02
问题 For example, if we have a table Books, how would we count total number of book records with hibernate? 回答1: For older versions of Hibernate (<5.2): Assuming the class name is Book: return (Number) session.createCriteria("Book") .setProjection(Projections.rowCount()) .uniqueResult(); It is at least a Number , most likely a Long . 回答2: In Java i usually need to return int and use this form: int count = ((Long)getSession().createQuery("select count(*) from Book").uniqueResult()).intValue(); 回答3: