Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Require minimum number of data points for resampling?

Is there a way to make it so that

df2=df2.resample('D',how="mean",label="left",closed="left")

Requires a certain number of points (say 10) to make up that average. And if there isn't NaN that Day

Data set looks like:

2004-02-27 20:00:00,2.5666666666666678,0.8638333333333333,,,,,,,,2.5666666666666678,,,,,,4.9,1.0,1.0,1.9088083333333328,0.0214,2.218625,0.0214,246.66666666666663,9.866666666666667,0.0,1.0,1.0
2004-02-27 21:00:00,8.216666666666667,0.95425,,,,,,,,8.216666666666667,,,,,,4.9,1.0,1.0,1.909341666666667,0.0214,2.2172416666666668,0.0214,251.91666666666663,11.308333333333335,0.0,1.0,1.0
2004-02-27 22:00:00,5.116666666666666,0.9855,,,,,,,,5.116666666666666,,,,,,4.9,1.0,1.0,1.9110833333333337,0.0214,2.2185916666666663,0.0214,257.1666666666667,12.54166666666667,0.0,1.0,1.0
like image 396
SLE Avatar asked Jan 18 '26 04:01

SLE


1 Answers

You can create a boolean mask that tells you where enough data points exist.

enough_points = df2.resample("D", label="left", closed="left").count() >= 10

Then calculate the means and filter them with the mask.

means = df2.resample("D", label="left", closed="left").mean()
good_means = means[enough_points]

like image 70
Dominik Avatar answered Jan 20 '26 17:01

Dominik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!