0

I am trying to perform a t-test with the following. It worked initially. But, now, it is showing the following error,

'numpy.float64' object has no attribute 'ttest_ind'

col=list(somecolumns)
for i in col:
    x = np.array(data1[data1.LoanOnCard == 0][i]) 
    y = np.array(data1[data1.LoanOnCard == 1][i])
    t, p_value  = stats.ttest_ind(x,y, axis = 0,equal_var=False) 
    if p_value < 0.05:  # Setting our significance level at 5%
        print('Rejecting Null Hypothesis. Loan holders and non-Loan holders are not same for',i,'P value is %.2f' %p_value)
    else:
        print('Fail to Reject Null Hypothesis. Loan holders and non-Loan holders are  same for',i,'P value is %.2f' %p_value)

I am struggling to find an answer to this. Cant able to resolve.

molbdnilo
  • 64,751
  • 3
  • 43
  • 82
  • It's not clear what `stats` is in this code. You say it worked before, have you by any chance made a variable called `stats`? – dm2 Jul 10 '21 at 16:54

1 Answers1

1

Add from scipy import stats to your code.

If you already did it, this means you likely overwrote stats with another object. Then you can do import scipy.stats and use scipy.stats.ttest_ind instead of stats.ttest_ind

mozway
  • 194,879
  • 13
  • 39
  • 75