Tschuprow association error - module 'scipy.stats.contingency' has no attribute 'association'

Viewed 72

I want to use tschuprow method for association between two variables: x and y. I cannot figure out if something is not imported or I understand this method wrong. Here's a link to scipy documentation: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.contingency.association.html#scipy.stats.contingency.association

imported libraries:

import pandas as pd
import numpy as np
import scipy

code:

x = df["tablename1"]
y = df["tablename2"]
scipy.stats.contingency.association(observed=[x,y],method='tschuprow')

following error appears:

module 'scipy.stats.contingency' has no attribute 'association'
1 Answers

Its small syntax error, observed should be n*m array. So, you need to convert it to array. Here is the code.

import pandas as pd
import numpy as np
import scipy

#obs = df[['tablename1', 'tablename2']].to_numpy()
      #OR
obs = np.array(df[['tablename1', 'tablename2']])
test= scipy.stats.contingency.association(obs,method='tschuprow')
print(test)

Hope, this will solve the error.

Related