I am doing independence test & try to find expected values, however I do not understand how to resolve this issue with traceback. Help me to find the problem in code, please.
#Exercise 6.46.
import matplotlib.pyplot as plt
import numpy as np
import math
import seaborn as sns
import pandas as pd
%matplotlib inline
data = pd.DataFrame([[264,299,351,264+299+351], [38,55,77,38+55+77], [16,15,22, 16+15+22], [318,369,450, 318+369+450]],
index=['Should', 'Should Not', 'No answer', "Total",],
columns=['Republican', 'Democrat', "Independent", "Total",])
print(data)
#Expected Values
col_sums= data.iloc[0:3,3].values
row_sums = data.iloc[3:4,0:3].values
print(col_sums)
print(row_sums)
total = data.loc['Total', 'Total']
print(total)
f_expected = []
for j in range(3):
for i in col_sums:
f_expected.append(i*row_sums[j]/total)
print(f_expected)
Here is the traceback: --- IndexError Traceback (most recent call last) in () 22 for j in range(3): 23 for i in col_sums: ---> 24 f_expected.append(i*row_sums[j]/total) 25 print(f_expected) 26
IndexError: index 1 is out of bounds for axis 0 with size 1
Aucun commentaire:
Enregistrer un commentaire