Skip to content
Advertisement

Join two columns of sequentially values

I have dataframe, where ‘A’ 1 – client, B – admin I need to merge messages in row with 1 sequentially and merge lines 2 – admin response sequentially across the dataframe. I do not know how to do this Answer Create groups by consecutive values in B – trick compare shifted values with cumulative sum and aggregate first and

Django View, foreign key field is killing performance

MyObjects definition: View definition: I do some calculations in my view that are irrelevant and my view takes around 3 seconds for 5000 objects if my_dict[str(my_obj.foreign_key_field)] += 1 is commented out. However, when that line uncommented, my view takes 20seconds. It must be because this field is a foreign key field as none of my other fields are foreign keys.

Sqlalchemy in-memory database for MSSQL

I’m trying to setup tests for my project and want to use an in memory database for those tests. Based on some examples I found online I’ve been able to get an in memory sqlite database working… The problem I have is my models are all based around MSSQL (that’s what the ‘real’ code is using) so I get E

Calculate the total days between a range of dates using Python

I have a list of date ranges and want to find the total number of days between those ranges. However, the ranges may, or may not, have overlap. And I want to exclude overlapped time. There may also be gaps between the ranges which I also want to exclude. I’m curious on the most optimal way to calculate this. An

keep the same name until value = true in another pandas column

I have a dataframe with 3 columns: session_id, name, reset_flag. I need to make a new column, new_name, where the new name will be set to the first name where reset_flag=True, and then it will continue as that name WITHIN that session, until there is new reset_flag. Not really sure best way to approach. EDIT: I thought of a way

Advertisement