TypeError: 'DataFrame' object is not callable TypeError: 'DataFrame' object is not callable numpy numpy

TypeError: 'DataFrame' object is not callable


It seems you need DataFrame.var:

Normalized by N-1 by default. This can be changed using the ddof argument

var1 = credit_card.var()

Sample:

#random dataframenp.random.seed(100)credit_card = pd.DataFrame(np.random.randint(10, size=(5,5)), columns=list('ABCDE'))print (credit_card)   A  B  C  D  E0  8  8  3  7  71  0  4  2  5  22  2  2  1  0  83  4  0  9  6  24  4  1  5  3  4var1 = credit_card.var()print (var1)A     8.8B    10.0C    10.0D     7.7E     7.8dtype: float64var2 = credit_card.var(axis=1)print (var2)0     4.31     3.82     9.83    12.24     2.3dtype: float64

If need numpy solutions with numpy.var:

print (np.var(credit_card.values, axis=0))[ 7.04  8.    8.    6.16  6.24]print (np.var(credit_card.values, axis=1))[ 3.44  3.04  7.84  9.76  1.84]

Differences are because by default ddof=1 in pandas, but you can change it to 0:

var1 = credit_card.var(ddof=0)print (var1)A    7.04B    8.00C    8.00D    6.16E    6.24dtype: float64var2 = credit_card.var(ddof=0, axis=1)print (var2)0    3.441    3.042    7.843    9.764    1.84dtype: float64