Pandas – groupby string field and select by time-of-day range

I have a dataset like this index Date_Time Pass_ID El 0 3/30/23 05:12:36.36 A 1 1 3/30/23 05:12:38.38 A 2 1 3/30/23 05:12:40.40 A 3 1 3/30/23 05:12:42.42 A 4 1 3/30/23 05:12:44.44 A 4 1 3/30/23 12:12:50.50 B 3 1 3/30/23 12:12:52.52 B 4 1 3/30/23 12:12:54.54 B 5 1 3/30/23 12:12:56.56 B 6… Read More Pandas – groupby string field and select by time-of-day range

How can I find the first row that meets conditions of a mask for each group?

This is my DataFrame: import pandas as pd df = pd.DataFrame( { ‘a’: [‘x’, ‘x’, ‘x’, ‘x’, ‘x’, ‘y’, ‘y’, ‘y’, ‘y’, ‘y’, ‘y’, ‘y’], ‘b’: [1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 2, 2], ‘c’: [9, 8, 11, 13, 14, 3, 104, 106, 11, 100, 70, 7] } ) Expected output:… Read More How can I find the first row that meets conditions of a mask for each group?

Some manipulations with groupby Pandas

I have this Dataframe import pandas as pd import math from pandas import Timestamp Date = [Timestamp(‘2024-03-16 23:59:42’), Timestamp(‘2024-03-16 23:59:42’), Timestamp(‘2024-03-16 23:59:44’), Timestamp(‘2024-03-16 23:59:44’), Timestamp(‘2024-03-16 23:59:44’), Timestamp(‘2024-03-16 23:59:47’), Timestamp(‘2024-03-16 23:59:48’), Timestamp(‘2024-03-16 23:59:48’), Timestamp(‘2024-03-16 23:59:49’), Timestamp(‘2024-03-16 23:59:49’), Timestamp(‘2024-03-16 23:59:49’), Timestamp(‘2024-03-16 23:59:49’), Timestamp(‘2024-03-16 23:59:49’), Timestamp(‘2024-03-16 23:59:49’), Timestamp(‘2024-03-16 23:59:49’), Timestamp(‘2024-03-16 23:59:49’), Timestamp(‘2024-03-16 23:59:49’), Timestamp(‘2024-03-16 23:59:49’), Timestamp(‘2024-03-16 23:59:49’), Timestamp(‘2024-03-16… Read More Some manipulations with groupby Pandas

How to select first N number of groups based on values of a column conditionally and groupby two columns?

This is a follow up to this post This is my DataFrame: df = pd.DataFrame( { ‘a’: [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 10, 22], ‘b’: [1, 1, 1, -1, -1, -1, -1, 2, 2, 2, 2, -1, -1, -1, -1], ‘c’: [25, 25, 25, 45, 45, 45,… Read More How to select first N number of groups based on values of a column conditionally and groupby two columns?