[英]How do I call from a dataset and have it compare two different data points in python?
I'm not very good with python.我对 python 不是很好。
You can use pandas library to access the values in the dataset which you wanted to use as a criterion to predict the win.您可以使用 pandas 库来访问数据集中您想用作预测获胜标准的值。 You should make a function and in it apply your way.
您应该制作一个 function 并以您的方式应用。
#Index-based selection¶
#Pandas indexing works in one of two paradigms. The first is index-based selection: selecting data based on its numerical position in the data. iloc follows this paradigm.
#To select the first row of data in a DataFrame, we may use the following:
df.iloc[0]
#to get a column
df.iloc[:, 0]
df.iloc[[0, 1, 2], 0]
#Label-based selection
#The second paradigm for attribute selection is the one followed by the loc operator: label-based selection. In this paradigm, it's the data index value, not its position, which matters.
#For example, to get the first entry in reviews, we would now do the following:
df.loc[0, 'country']
df.loc[:, ['taster_name', 'taster_twitter_handle', 'points']]
cols=['dc','adfa','fas']
indiecs-[0,1,10,14]
df.loc[indiecs,cols]
I added a few extras in there, but basically,我在那里添加了一些额外的东西,但基本上,
Code:代码:
#pip install fuzzywuzzy
#pip install choice
import pandas as pd
import numpy as np
from fuzzywuzzy import process
import choice
df = pd.read_csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vSTbHMm7RQOxOj6yl17g7MLfCBFghAACUie0k3HLB_ja9E0t0HpENl4ydN4b58UdCCiBTB9rvj0zy-O/pub?output=csv")
choices = list(df['PLAYER'])
def select_player(choices, player_no):
player = input('Type player %s: ' %player_no)
if 100 not in [x[1] for x in process.extract(player, choices, limit=5)]:
print('Which player did you mean?')
player = choice.Menu([x[0] for x in process.extract(player, choices, limit=5)]).ask()
else:
player = process.extract(player, choices, limit=5)[0][0]
print('You selected: %s' %player)
return player
def play_game(player_1, player_2):
player_1_stats = df[df['PLAYER'] == player_1]
player_2_stats = df[df['PLAYER'] == player_2]
score = player_1_stats.append(player_2_stats).reset_index(drop=True)
num_cols = list(score.select_dtypes('number').columns)
for col in num_cols:
winning_score = score[col].max()
score[col] = np.where(score[col] == winning_score, 1,0)
score['Total'] = score[num_cols].sum(axis=1)
print(score[['PLAYER','Total']])
player_1 = select_player(choices, 1)
player_2 = select_player(choices, 2)
play_game(player_1, player_2)
Output: Output:
Type player 1: james harden
You selected: James Harden
Type player 2: Jim Butler
Which player did you mean?
Make a choice:
0: Jimmy Butler
1: Ben Simmons
2: Devin Booker
Enter number or name; return for next page
? 0
You selected: Jimmy Butler
PLAYER Total
0 James Harden 4
1 Jimmy Butler 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.