赞
踩
import numpy as np
np.zeros(shape, dtype=float, orser='c')
使用独热编码对数据信息进行存储:
import numpy as np import matplotlib.pyplot as plt import matplotlib import pandas as pd import sklearn df = pd.DataFrame({"num":["A, C, D", "H, A, B", "C, B, F", "S, A, L"]}) temp_list = df["num"].str.split(", ").tolist() num_list = list(sorted(set([i for j in temp_list for i in j]))) zeros_df = pd.DataFrame(np.zeros((df.shape[0], len(num_list))), dtype=np.int16, columns=num_list) for i in range(df.shape[0]): zeros_df.loc[i, temp_list[i]] = 1 print(zeros_df)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。