import numpy as np import pandas as pd recommond_matrix=np.zeros((3,4)) headers=['用户','食物','评分'] df_rate=pd.read_csv('rate.csv',sep='s',names=headers) print(df_rate) print('************************************************') for item in df_rate.itertuples(): recommond_matrix[item[1]-1][item[2]-1]=item[3] print(recommond_matrix)
import numpy as np import pandas as pd recommond_matrix=np.zeros((3,4)) headers=['用户','食物','评分'] df_rate=pd.read_csv('rate.csv',sep='s',names=headers) print(df_rate) print('************************************************') for item in df_rate.itertuples(): recommond_matrix[item[1]-1][item[2]-1]=item[3] print(recommond_matrix)