Get max value in previous rows for matching rows

Say I have a dataframe that records temperature measurements for various sensors: import pandas as pd df = pd.DataFrame({‘sensor’: [‘A’, ‘C’, ‘A’, ‘C’, ‘B’, ‘B’, ‘C’, ‘A’, ‘A’, ‘A’], ‘temperature’: [4.8, 12.5, 25.1, 16.9, 20.4, 15.7, 7.7, 5.5, 27.4, 17.7]}) I would like to add a column max_prev_temp that will show the previous maximum temperature… Read More Get max value in previous rows for matching rows

Calculate stdev for a row and previous row in pandas without series error

Here is my dataset Date,p1Close,p2Close, spread, movingAverage 2022-02-28,5,10,2,NaN 2022-03-01,2,6,3,2.5 2022-03-02,4,8,2,2,5 2022-03-03,2,8,4,3 I am trying to create a new column in pandas data frame that is equal to the standard deviation between ‘spread’ from previous row and current row. df[‘standardDeviation’] = statistics.stdev(df[‘spread’], df[‘spread’].shift(1)) I keep getting this error: File "/usr/lib/python3.9/statistics.py", line 797, in stdev var =… Read More Calculate stdev for a row and previous row in pandas without series error

Sum of rolling groupby based on date not returning expected results

I have the following DataFrame: match_date player_id player__match_count__won 1 2012-09-25 10:00:00 23640 1 18 2012-09-25 10:00:00 17969 0 2 2012-09-26 16:00:00 17268 1 19 2012-09-26 16:00:00 11247 0 0 2012-09-25 00:00:00 23640 1 17 2012-09-25 00:00:00 17268 0 3 2012-09-29 00:00:00 12202 1 20 2012-09-29 00:00:00 23640 0 5 2012-10-02 14:20:00 9241 1 22 2012-10-02… Read More Sum of rolling groupby based on date not returning expected results