Python - Correlation Test with Numpy

Viewed 538

I am attempting to analyse the World cup data, I want to make a correlation between the times the games start at and the goals scored. Im hoping this shows that a time may produce more goals.

My dataset is in a csv file and contains the following headings and 1 row of data as an example:

enter image description here

I am attempting to write the correlation test in python but am having some problems with it.

My question: How do I prove/disprove there is a correlation between times the matches are played at and the amount of goals scored?

import pandas as pd
from scipy import stats
import numpy as np

#Read the data into a dataframe
df = pd.read_csv("World Cup 2018.csv")

index2 = df.loc[df['start_time']]
print(index2['home_score'])

Test = numpy.corrcoef(index2.start_time, index2.home_score)[0, 1]
print(Test)
1 Answers

Have you tried the Pandas correlation function?

df.corr()[['start_time']].sort_values('start_time')

It will give you a set of values for each column in the data frame, and how much it correlates to the start_time: home_team -0.123456 away_team -0.789012 home_score -0.890123 away_score -0.901234 The higher the score, the more the two values seem correlated. While it's not a hard and fast rule, a correlation greater than +0.8 is a strong relation

Related