group-by

date range for six monthly in pandas

感情迁移 提交于 2019-12-21 20:59:36
问题 So, this is my data frame. PatientNumber QT Answer Answerdate DiagnosisDate 1 1 transferring No 2017-03-03 2018-05-03 2 1 preparing food No 2017-03-03 2018-05-03 3 1 medications Yes 2017-03-03 2018-05-03 4 2 transferring No 2011-05-10 2012-05-04 5 2 preparing food No 2011-05-10 2012-05-04 6 2 medications No 2011-05-10 2012-05-04 7 2 transferring Yes 2011-15-03 2012-05-04 8 2 preparing food Yes 2011-15-03 2012-05-04 9 2 medications No 2011-15-03 2012-05-04 10 2 transferring Yes 2010-15-12 2012

Group a collection in MVC View and update model in controller?

爷,独闯天下 提交于 2019-12-21 20:23:28
问题 I have a View that displays a collection from a ViewModel, where the user can update a property for each collection item ("Level" of proficiency). Here's the View: @model Consultants.ViewModels.ProgramsViewModel @{ ViewBag.Title = "Programkunskaper"; } <h2>@ViewBag.Title</h2> <div id="formDiv"> @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "myForm" })) { @Html.ValidationSummary(true) <fieldset> <legend>Ny arbetserfarenhet</legend> <table> <tr> <th> Program </th> <th> Nivå <

How to randomly split data into three equal sizes?

久未见 提交于 2019-12-21 20:14:50
问题 I have a dataset with 9558 rows from three different projects. I want to randomly split this dataset in three equal groups and assign a unique ID for each group, so that Project1_Project_2_Project3 becomes Project1 , Project2 and Project3 . I have tried many things, and googled codes from people with similar problem as I have. I have used sample_n() and sample_frac() , but unfortunately I can't solve this issue myself :/ I have made an example of my dataset looking like this: ProjectName <- c

Customizing rolling_apply function in Python pandas

只愿长相守 提交于 2019-12-21 20:04:03
问题 Setup I have a DataFrame with three columns: "Category" contains True and False, and I have done df.groupby('Category') to group by these values. "Time" contains timestamps (measured in seconds) at which values have been recorded "Value" contains the values themselves. At each time instance, two values are recorded: one has category "True", and the other has category "False". Rolling apply question Within each category group , I want to compute a number and store it in column Result for each

Counting Instances of Unique Value in Field

北慕城南 提交于 2019-12-21 17:37:46
问题 Suppose you have a table in SQL: Prices ------ 13.99 14.00 52.00 52.00 52.00 13.99 How would you count the amount of times a DIFFERENT field has been entered in? Therefore an example of such a count would output: 13.99 - 2 times. 14.00 - 1 times. 52.00 - 3 times. OR perhaps: 3 (i.e. 13.99, 14.00, 52.00) Can anyone advise? Cheers. 回答1: How about: SELECT Prices, COUNT(*) FROM TheTable GROUP BY Prices Can't say I've tried it on MySql, but I'd expect it to work... 来源: https://stackoverflow.com

Function similar to group_by when groups are not mutually exlcusive

孤人 提交于 2019-12-21 17:26:10
问题 I would like to create a function in R, similar to dplyr 's group_by function, that when combined with summarise can give summary statistics for a dataset where group membership is not mutually exclusive . I.e., observations can belong to multiple groups. One way to think about it might be to consider tags; observations may belong to one or more tags which might overlap. For example, take R's esoph dataset (https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/esoph.html) documenting a

Mysql: Count records (including zero) per month

狂风中的少年 提交于 2019-12-21 17:01:32
问题 I am trying to count the records in my table and group them per date. My current query looks something like the following: SELECT count(*), MONTH(time) as month, YEAR(time) as year FROM myTable GROUP BY month, year ORDER BY year, month This works, except that I would also like to get a count for months where no records exists. Could anyone offer advice/suggestions on how to accomplish this? 回答1: The simplest way to do this in MySQL is to create a table called months that lists all the months

How to group by week in Entity Framework Core?

佐手、 提交于 2019-12-21 16:15:10
问题 In Entity Framework 6 I can use SqlFunctions.DatePart() method: var byWeek = data.GroupBy(x => SqlFunctions.DatePart("week", x.Date)); But these classes ( DbFunctions and SqlFunctions are not available in Entity Framework Core) (reference). So my question is How can I group by week in Entity Framework core? 回答1: My current workaround for the missing functionality is var firstMondayOfYear = this.GetFirstMondayOfYear(DateTime.Now.Year); var entries = this.entitiesService.FindForLastMonths(this

Faster way to groupby time of day in pandas

房东的猫 提交于 2019-12-21 16:05:12
问题 I have a time series of several days of 1-minute data, and would like to average it across all days by time of day. This is very slow: from datetime import datetime from pandas import date_range, Series time_ind = date_range(datetime(2013, 1, 1), datetime(2013, 1, 10), freq='1min') all_data = Series(randn(len(time_ind)), time_ind) time_mean = all_data.groupby(lambda x: x.time()).mean() Takes almost a minute to run! While something like: time_mean = all_data.groupby(lambda x: x.minute).mean()

Sequel: How to use group and count

蓝咒 提交于 2019-12-21 13:04:25
问题 Simply put, how can I do this query using Sequel? select a.id, count(t.id) from albums a right join tracks t on t.album_id = a.id group by a.id 回答1: DB[:albums___a]. right_join(:tracks___t, :album_id=>:id). select_group(:a__id). select_more{count(:t__id)} 回答2: Your problem is that the left join finds a track ID for each album ID. Solutions: right join subquery of sums, assuming sequel supports that: left join (select album_id, count(album_id) as count from tracks group by album_id) t on a