pandas : sum with lagged param

in sql request, i have a chance to sum with lagged param on the fly, like: CASE WHEN dt_rep.fcr = 0::numeric THEN 0::numeric ELSE (dt_rep.fcr – lag(dt_rep.fcr) OVER (PARTITION BY dt_rep.place_id ORDER BY dt_rep.bucket)) / dt_rep.fcr END AS cr here, I order the table by bucket (it is timeframe) and sorted them by place_id (to… Read More pandas : sum with lagged param

Pyspark windows function: preceding and following event

I have the following dataframe in pyspark: +——————- +——————-+———+———————–+———–+ |device_id |order_creation_time|order_id |status_check_time |status_code| +——————–+——————-+———+———————–+———–+ |67a-05df-4ca5-af6ajn|2022-11-26 23:54:41|105785113|2022-11-26 23:55:33.858|200 | |67a-05df-4ca5-af6ajn|2022-11-26 23:54:41|105785113|2022-11-26 23:55:13.1 |200 | |67a-05df-4ca5-af6ajn|2022-11-26 23:54:41|105785113|2022-11-26 23:54:57.682|200 | |67a-05df-4ca5-af6ajn|2022-11-26 23:54:41|105785113|2022-11-26 23:54:36.676|200 | |67a-05df-4ca5-af6ajn|2022-11-26 23:54:41|105785113|2022-11-26 23:54:21.293|200 | +——————–+——————-+———+———————–+———–+ I need to get the time of the status_check_time immediately preceding, and immediately after the order_creation_time. The order_creation_time column… Read More Pyspark windows function: preceding and following event

Python Optimize multiple if-else based on truthy value

I have following code in Python where based on a boolean flag I need to check a list count, wondering if there is a better way to code this in Python? If var_true: if len(something) > 0: logger.console (“Something found”) else: raise AssertionError(“something was not found”) If not var_true: if len(something) == 0: logger.console (“Something… Read More Python Optimize multiple if-else based on truthy value

Retrive only replacement template of regex in C#

can i get only the substitution of the Regex.Replace? Example. String text = @"asdfgs sda gsa ga s SECTOR:124 NAME:Ricko asdfgs sda gsa ga s"; String regex = "^SECTOR:(\d+) NAME:(\w+)"; String substitution = "$2 $1"; String result = Regex.Replace(text, regex, substitution); Console.WriteLine(result); Normal result asdfgs sda gsa ga s Ricko 124 Wanted result Ricko 124… Read More Retrive only replacement template of regex in C#

Change background color of combined plots in ggpubr::ggarrange

I can’t figure out why the bottom corners background is white, while the rest of the plot is grey. Is there anyway I can change the bottom corners color to the same background as the rest of the plot? The code im using for each plot is: HP_specifikationer_model1 <- ggplot(Svar_spec_data)+geom_hline(yintercept=0) geom_line(aes(y=HP1, x=kvartaler, color = "HP-BNP-KRE-REN"))… Read More Change background color of combined plots in ggpubr::ggarrange