Srikanth Ayithy
Srikanth Ayithy

Reputation: 99

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

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.

Upvotes: 0

Views: 781

Answers (1)

mozway
mozway

Reputation: 260300

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

Upvotes: 1

Related Questions