希望您能提供帮助。
我正在使用fifa20数据集,其中包含约85个描述玩家的变量。我想使用6个变量:attack_finishing,skill_dribbling,power_long_shots,skill_ball_control,mindality_positioning和mentality_penalties。
我有以下简单的公式,它描述了这些变量的玩家值:
attack_finishing:70 技术运球:65 power_long_shots:74 skill_ball_control:67 心态定位:80 mental_penalties:70
进入simpe公式: G_分数=(0.25 * 70)+(0.15 * 65)+(0.1 * 74)+(0.2 * 67)+(0.1 * 80)+(0.2 * 70) G_Score = 65.05
我的意图是构建一个函数,在其中可以使用数据集中的名称调用该函数,并且它将根据上述变量中的玩家值为我提供该玩家的G_Score。
我尝试使用以下代码:
import pandas as pd
fifa20 = pd.read_csv('players_20.csv',delimiter=',')
def Gscore(long_name): --> create the function,which takes the name of the player(long_name)
for i in fifa20(attacking_finishing,skill_dribbling,power_long_shots,skill_ball_control,mentality_positioning,mentality_penaltites): --> the variables the function should take in fifa20 dataset
i = (0.25 * 'attacking_finishing') + (0.15 * 'skill_dribbling') + (0.1 * 'power_long_shots') + (0.2 * 'skill_ball_control') + (0.1 * 'mentality_positioning') + (0.2 * 'mentality_penalties') --> try to put the formular in here
retrun (i) --> return the sum
Gscore('Alan Pulido') --> me calling trying to call the function,with a player name
我没有从函数中得到一个错误,但是当我尝试调用时,我得到了:
NameError: name 'attacking_finishing' is not defined
我现在知道,这里有很多错误。
数据集的格式如下
谢谢!