aggregate

Group by date to get count of hits for a day, for last 7 days and for a months

别说谁变了你拦得住时间么 提交于 2020-06-17 14:09:51
问题 [{'_id': '5ebe39e41e1729d90de', 'modelId': '5ebe3536c289711579', 'lastAt': datetime.datetime(2020, 5, 15, 6, 42, 44, 79000), 'proId': '5ebe3536c2897115793dccfb', 'genId': '5ebe355ac2897115793dcd04'}, {'_id': '5ebe3a0d94fcb800fa474310', 'modelId': '5ebe3536c289711579', 'proId': '5ebe3536c2897115793d', 'genId': '5ebe355ac2897115793', 'lastAt': datetime.datetime(2020, 5, 15, 6, 43, 25, 105000)}] I want to calculate count of hits for a day, for last 7 days and for a months. As the model is same,

Group by date to get count of hits for a day, for last 7 days and for a months

北战南征 提交于 2020-06-17 14:03:40
问题 [{'_id': '5ebe39e41e1729d90de', 'modelId': '5ebe3536c289711579', 'lastAt': datetime.datetime(2020, 5, 15, 6, 42, 44, 79000), 'proId': '5ebe3536c2897115793dccfb', 'genId': '5ebe355ac2897115793dcd04'}, {'_id': '5ebe3a0d94fcb800fa474310', 'modelId': '5ebe3536c289711579', 'proId': '5ebe3536c2897115793d', 'genId': '5ebe355ac2897115793', 'lastAt': datetime.datetime(2020, 5, 15, 6, 43, 25, 105000)}] I want to calculate count of hits for a day, for last 7 days and for a months. As the model is same,

pandas DataFrame: aggregate values within blocks of repeating IDs

梦想的初衷 提交于 2020-06-16 19:56:45
问题 Given a DataFrame with an ID column and corresponding values column, how can I aggregate (let's say sum) the values within blocks of repeating IDs? Example DF: import numpy as np import pandas as pd df = pd.DataFrame( {'id': ['a', 'a', 'a', 'a', 'a', 'b', 'b', 'b', 'a', 'a', 'b', 'a', 'b', 'b', 'b'], 'v': np.ones(15)} ) Note that there's only two unique IDs, so a simple groupby('id') won't work. Also, the IDs don't alternate/repeat in a regular manner. What I came up with was to recreate the

pandas DataFrame: aggregate values within blocks of repeating IDs

戏子无情 提交于 2020-06-16 19:55:07
问题 Given a DataFrame with an ID column and corresponding values column, how can I aggregate (let's say sum) the values within blocks of repeating IDs? Example DF: import numpy as np import pandas as pd df = pd.DataFrame( {'id': ['a', 'a', 'a', 'a', 'a', 'b', 'b', 'b', 'a', 'a', 'b', 'a', 'b', 'b', 'b'], 'v': np.ones(15)} ) Note that there's only two unique IDs, so a simple groupby('id') won't work. Also, the IDs don't alternate/repeat in a regular manner. What I came up with was to recreate the

How to count related rows including subcategories?

陌路散爱 提交于 2020-06-16 17:24:13
问题 I've got a few tables in a Postgres 12.3 database. The first one is named category : id|template_id|name |entry_count|is_base_template|can_rename|can_delete|section|userId|parentCategoryId| --|-----------|---------------|-----------|----------------|----------|----------|-------|------|----------------| 1| |Notes | 0|true |true |true |A | | | 2| |ToDo | 0|true |true |true |A | | | 3| 1|Notes | 0|false |true |true |A | 1| | 4| 2|ToDo | 0|false |true |true |A | 1| | 5| |Must Do | 0|false | | |A

Solution for SpecificationError: nested renamer is not supported while agg() along with groupby()

有些话、适合烂在心里 提交于 2020-06-08 08:06:10
问题 def stack_plot(data, xtick, col2='project_is_approved', col3='total'): ind = np.arange(data.shape[0]) plt.figure(figsize=(20,5)) p1 = plt.bar(ind, data[col3].values) p2 = plt.bar(ind, data[col2].values) plt.ylabel('Projects') plt.title('Number of projects aproved vs rejected') plt.xticks(ind, list(data[xtick].values)) plt.legend((p1[0], p2[0]), ('total', 'accepted')) plt.show() def univariate_barplots(data, col1, col2='project_is_approved', top=False): # Count number of zeros in dataframe

R combining duplicate rows by ID with different column types in a dataframe

こ雲淡風輕ζ 提交于 2020-06-01 05:59:27
问题 I have a dataframe with a column ID as an identifier and some other columns of different types (factors and numerics). It looks like this df <- data.frame(id = c(1, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4), abst = c(0, NA, 2, NA, NA, NA, 0, 0, NA, 2, NA, 3, 4), farbe = as.factor(c("keine", NA, "keine", NA, NA, NA, "keine", "keine", NA, NA, NA, "rot", "rot")), gier = c(0, NA, 5, NA, NA, NA, 0, 0, NA, 1, NA, 6, 2)) Now I want to combine the duplicate IDs. The numeric columns are defined as the mean

Does everything have to be an aggregate? Many-to-Many Link

一笑奈何 提交于 2020-06-01 05:50:15
问题 Say I have two entities Notifications and Users. I want to mark that a user has seen a specific notification. This would commonly be done with a many-to-many relationship e.g. UserNotification Because there is no invariant around this relationship (we don't care if "all" users have seen the notification) these users shouldn't be on the notification aggregate. On the opposite side, the users aggregate doesn't need a list of notifications on it So that leads to say that the UserNotification

R combining duplicate rows in a time series with different column types in a datatable

本秂侑毒 提交于 2020-05-29 10:51:22
问题 The bounty expires tomorrow . Answers to this question are eligible for a +50 reputation bounty. Bolle is looking for an up-to-date answer to this question. This question is building up on another question R combining duplicate rows by ID with different column types in a dataframe. I have a datatable with a column time and some other columns of different types (factors and numerics). Here is an example: dt <- data.table(time = c(1, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4), abst = c(0, NA, 2, NA,

Finding max occurrence of a column's value, after group-by on another column

老子叫甜甜 提交于 2020-05-27 06:45:07
问题 I have a pandas data-frame: id city 000.tushar@gmail.com Bangalore 00078r@gmail.com Mumbai 0007ayan@gmail.com Jamshedpur 0007ayan@gmail.com Jamshedpur 000.tushar@gmail.com Bangalore 00078r@gmail.com Mumbai 00078r@gmail.com Vijayawada 00078r@gmail.com Vijayawada 00078r@gmail.com Vijayawada I want to find id-wise the maximum occurring city name. So that for a given id I can tell that - this is his favorite city: id city 000.tushar@gmail.com Bangalore 00078r@gmail.com Vijayawada 0007ayan@gmail