The Problem - If I input more than one player's names. Only the first name comes up and the program then stops. What can I do to print all names and the W/R Percentage presented by User's Input.
The code -
def print_player_data():
nba_data = pd.read_csv("csv_data.csv", sep=",")
dataList = []
player_names = input("Enter a list of player names: ")
player_names = player_names.split(",")
print(player_names)
for player in player_names:
for index, row in nba_data.iterrows():
if row["PLAYER_NAME"] == player:
dataList.append(row["W/R_percentage"])
print(dataList)
print_player_data()
The Data -
PLAYER_NAME,TEAM_ABBREVIATION,Player Impact Rating,GP,Wins,Losses,W/R_percentage
Alex Len,ATL,0.1,77,28,49,36.36
Alex Poythress,ATL,0.069,21,7,14,33.33
Daniel Hamilton,ATL,0.07,19,7,12,36.84
DeAndre Bembry,ATL,0.081,82,29,53,35.37
CodePudding user response:
It seems like when inputting the names, you add spaces after the comma. Add this line before iterating through your list to remove leading whitespaces:
player_names = [name.lstrip() for name in player_names]