I have football prediction algorithm output in csv. I have to initially add two columns, predicted_home_score & predicted_away_score to get total predicted goals. Then I have to set_axis to include this new column "Total_predicted_goal".
Now I sorted the values using total_predicted goals - df1 = df.sort_values(by=["total_predicted_goals"], ascending= False)
I only wanted the top 10 highest scores so i can slit it into two to predict the top 5 as over 2.5 and the remainder as over 1.5 --
My problem is that I want the output date to be in seqeunce.
def over_goals(request):
df = pd.read_csv("media/csv/predictions_with_gridsearch.csv")
df = df[['match_datetime', 'country', 'league', 'home_team', 'away_team', 'home_odds', 'draw_odds', 'away_odds', 'predicted_home_score', 'predicted_away_score']]
df['total_predicted_goals'] = df['predicted_home_score'] + df['predicted_away_score']
df = df.set_axis(['Match_Datetime', 'Country', 'League', 'Home_team', 'Away_team','home_odds', 'draw_odds', 'away_odds','Predicted_home_score', 'Predicted_away_score', 'total_predicted_goals'], axis=1)
df1 = df.sort_values(by=["total_predicted_goals"], ascending= False)
df1 = df1.drop(['home_odds', 'draw_odds', 'away_odds'], axis=1)
df1 = df1.head(10)
dt = ['Over 2.5', 'Over 2.5', 'Over 2.5', 'Over 2.5', 'Over 2.5', 'Over 1.5', 'Over 1.5','Over 1.5','Over 1.5','Over 1.5']
df1['Prediction'] = dt
df2 = df1.drop(['Predicted_home_score', 'Predicted_away_score', 'total_predicted_goals'], axis=1)
df2 = df2.style
goals = df2.to_html()
return render(request, 'over_goals.html', {
'goals': goals
})
note i have seen this question - How to sort a dataFrame in python pandas by two or more columns?
Please see images code output data