【发布时间】:2018-06-02 20:36:59
【问题描述】:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
style.use("fivethirtyeight")
df_2010=pd.read_csv("c:/users/ashub/downloads/documents/MLB 2010.csv",index_col=0)
df_new=df_2010[["Home Score","Away Score","Home Team","Away Team","Home Hits","Away Hits","Home Err","Away Err"]]
#print(df_2010)
flag=df_2010["Home Score"]>df_2010["Away Score"]
df_new["Home Score Index"]= flag.astype(int)
df_new["Away Score Index"]= (~flag).astype(int)
flag1=df_2010["Home Score"]/df_2010["Home Hits"]
df_new["Home to Hits Index"]= flag1.astype(float)
flag1=df_2010["Away Score"]/df_2010["Away Hits"]
df_new["Away to Hits Index"]= flag1.astype(float)
flag1=df_2010["Home Err"]/df_2010["Home Score"]
df_new["Home Error Factor"]= flag1.astype(float)
flag1=df_2010["Away Err"]/df_2010["Away Score"]
df_new["Away Error Factor"]= flag1.astype(float)
df_new["Home Error Factor"].fillna(0,inplace=True)
df_new["Away Error Factor"].fillna(0,inplace=True)
wins_home=sum(df_new["Home Score Index"].tolist())
total_games=len(df_2010)
prob_win_at_home=wins_home/total_games
prob_lose_at_home=1-prob_win_at_home
print(prob_win_at_home)
print(prob_lose_at_home)
df_new.to_html("c:/users/ashub/desktop/ashu.html")
现在我想计算特定球队在主场比赛的总场数中的获胜场次,我也想计算客场球队的获胜场次。如何处理这个?
【问题讨论】:
标签: python python-3.x pandas