The Pandas core resample Resampler function first() used to compute the first non-null entry of each group. It returns a Series or DataFrame that includes the first non-null of values within each group.
1 Resampler.first(numeric_only = False, min_count = 0, *args, **kwargs)
numeric_only : It is an boolean value that specifies whether to include only float, int, boolean columns. If not specified, the default value will be False.
min_count : It is an integer that specifies the required number of valid values to perform the operation. If fewer than min_count non-NA value are presents the result will be NA. If not specified, the default value will be -1.
*args : It specifies an additional arguments to be passed to the function.
**kwargs : It specifies an additional keywords to be passed to the function.
1 import pandas as pd
2
3 idx = pd.DatetimeIndex(['2023-01-01', '2023-01-5', '2023-01-10', '2023-01-15'])
4 ser = pd.Series([1, 2, None, 3], index = idx)
5
6 sample = ser.resample('6D')
7
8 res = sample.first()
9 print('The unique group counts :')
10 print(res)
In the above example, a Series object is created by passing an array and index. A Resampler function first() is called that returns a first non-null entry of each group. The result is assign to the variable that will be printed on console.
1 The unique group counts :
2 2023-01-01 1.0
3 2023-01-07 NaN
4 2023-01-13 3.0
5 Freq: 6D, dtype: float64
first() with min_count
1 import pandas as pd
2
3 idx = pd.DatetimeIndex(['2023-01-01', '2023-01-5', '2023-01-10', '2023-01-15'])
4 ser = pd.Series([1, 2, None, 3], index = idx)
5
6 sample = ser.resample('6D')
7
8 res = sample.first(min_count = 2)
9 print('The unique group counts :')
10 print(res)
In the above example, a Resampler function first() is called by passing a min_count parameter that specifies the min non-NA entries of each group.
1 The unique group counts :
2 2023-01-01 1.0
3 2023-01-07 NaN
4 2023-01-13 NaN
5 Freq: 6D, dtype: float64
Related options for your search