Is there a way to save & use the cut_bins values from pd.cut() into a different file

27 Views Asked by At

I am using the pd.cut() to do binning of a numerical column in df as below

train_df['bucket'], cut_bins = pd.qcut(train_df['rank'] , q=10, labels=[1,2,3,4,5,6,7,8,9,10], retbins=True)

And I can use the cut_bins values to bin my test data as well as below,

test_df['bucket'] = pd.cut(test_df['rank'], bins=cut_bins, labels=False, include_lowest=True)

So, now the situation is that the model was saved as a .pkl file. Whenever a new user wants to loads the model how can they use this cut_bins value that was gotten from the train_df and do the similar binning in their new_df.

Any help is much appreciated

Thanks,

0

There are 0 best solutions below