Search code examples
pythonpandasstat

t-test module issue python


I am working with t-test on a pandas dataframe. I have about 40 attributes and one target variable.

I am using this piece of code for t-test analysis:

stats.ttest_ind(df[df['target']==1]['variable'], df[df['target']==0]['variable'])

I have imported the necessary modules as well:

from scipy import stats

However, I keep getting this error, and am not sure what am I doing wrong:

AttributeError                            Traceback (most recent call last)
<ipython-input-187-dbb554ef9ddf> in <module>()
----> 1 stats.ttest_ind(df[df['target']==1]['variable'], 
df[df['target']==0]['variable'])

AttributeError: 'function' object has no attribute 'ttest_ind'

Can anyone suggest some solution for this, I have been working on this issue for hours and don't know what's wrong.


Solution

  • Try

    from scipy.stats import ttest_ind
    
    ttest_ind(df[df['target']==1]['variable'], df[df['target']==0]['variable'])
    

    Is there a function called stats in your code?

    def stats(x):
        print(x)
    
    stats.ttest_ind()
    

    AttributeError: 'function' object has no attribute 'ttest_ind'