1 year ago

#385283

test-img

ruslaniv

How to use datetime column for sample weights in pandas

I know that I can randomly select n number of rows from pandas DataFrame by using pd.sample method.

One the columns I have is a datetime column:

datetime64[ns, UTC]

How can I use that datetime column as weights for sampling?

I'd like to draw more samples from more recent rows (like this month) versus older rows (like 2 years ago)

Naive approach was just passing this column as weights argument:

df_sampled = df.sample(n=20_000, weights='order_created_at')

but it raises an error:

TypeError: No matching signature found

python

pandas

dataframe

sample

0 Answers

Your Answer

Accepted video resources