简体   繁体   English

如何从数据集中调用并让它比较 python 中的两个不同数据点?

[英]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,我在那里添加了一些额外的东西,但基本上,

  1. You need to somehow get the inputs of the 2 players you want.你需要以某种方式获得你想要的 2 个玩家的输入。
  2. Filter out your dataframe to get those particular player stats过滤掉你的 dataframe 以获得那些特定的球员统计数据
  3. Compare those stats and score them in some way比较这些统计数据并以某种方式对它们进行评分
  4. Sum up the scores for each category/colum总结每个类别/列的分数
  5. Print out the results打印结果

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.

相关问题 如何比较两个不同长度的Python Pandas系列? - How do I compare two Python Pandas Series of different lengths? 如何比较取自 python 中不同 excel 文件的两列 - How do I compare two columns taken from different excel files in python 如何从Python中两个不同数据框中的两个不同索引中提取信息? - How do I do extract information from two different indices in two different data frames in Python? 如何比较来自不同文件夹的两个文本文件? - How do I compare two text files from different folders? 如何修复我的 Pandas 代码,以便正确比较来自两个不同时间点的观察结果? - How can I fix my pandas code so that it will correctly compare observations from two different points in time? 如何成对调用两个不同列表中的值,以指定Python中两个顺序刺激的参数? - How do I call values from two different lists, in pairs, to specify parameters of two sequential stimuli in Python? 使用python如何同时连接到两个不同的api,以便可以比较数据? - Using python how do I connect to two different api s at the same time so I can compare data? 如何在我的主数据框中创建一个新列,根据它们共有的两列填充较小数据集中的值? - how do I create a new column in my main data frame filling in the values from a smaller dataset based on two columns they have in common? 如何在Python中比较两个SQLlite数据集并寻找相似之处? - How can I compare two SQLlite dataset in Python and search for similarities? 如何比较 python 中的两个 arrays? - How do I compare two arrays in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM