Suppose you have a dataset that has float values and all values in the range 0 to 1.
You want to change all values to integer with a range between 10 to 20.
In this post we will learn how to do this using MinMaxScaler
Now let us scale the data as below
# convert the data to a given range from sklearn.preprocessing import MinMaxScaler scaler = MinMaxScaler(feature_range=(0, 10)) dfx = scaler.fit_transform(dfx.values.reshape(-1, 1)) scaler = MinMaxScaler(feature_range=(20, 50)) dfx = scaler.fit_transform(dfx.values.reshape(-1, 1)) dfx.head()
Data after Scaling is as below
You can also round all the float data above to nearest integer as below
dfx = dfx.round(0) # rounds to nearest integer import numpy as np dfx = dfx.applymap(np.int64)
I home you will find these code useful