For the fields of the data set, please binarize the field absence of the data set

Please perform binarization processing on the field absence of the data set. If it is more than 8 times, it is recorded as 1, and if it is not more than 8 times, it is recorded as 0. Save the processed result as the new column new_absence of the data set.

Tip: You can use the Binarizer function in sklearn.preprocessing to achieve the above functions

import pandas as pd
data = pd.read_csv('newdata.csv')
print(data[['absences']].head())

# 二值化转换
from sklearn import preprocessing
binarizer = preprocessing.Binarizer(threshold=8)
data['new_absences'] = binarizer.transform(data[['absences']])
 
print(data[['new_absences']].head())

Guess you like

Origin blog.csdn.net/weixin_44039266/article/details/106074166