Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

You must login to add post.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Passionable Logo Passionable Logo
Sign InSign Up

Passionable

Passionable Navigation

  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • New Questions
  • Trending Questions
  • Must read Questions
  • Hot Questions
Home/ Questions/Q 8841
In Process
Alek Richter
  • 0
Alek RichterEnlightened
Asked: January 11, 20222022-01-11T09:21:16+00:00 2022-01-11T09:21:16+00:00

TypeError: ‘DataFrame’ object is not callable

  • 0

I’ve programmed these for calculating Variance

import pandas as pd
import xlrd
import numpy as np
import matplotlib.pyplot as plt


credit_card=pd.read_csv("default_of_credit_card_clients_Data.csv",skiprows=1)

print(credit_card.head())
for col in credit_card:
    var[col]=np.var(credit_card(col))

print(var)

I’m getting this error

Traceback (most recent call last):
   File "C:/Python34/project.py", line 11, in <module>
     var[col]=np.var(credit_card(col)) TypeError: 'DataFrame' object is not callable
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
    • Report
  • Share
    Share
    • Share on Facebook
    • Share on Twitter
    • Share on LinkedIn
    • Share on WhatsApp

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Alek Richter Enlightened
    2022-01-11T09:21:37+00:00Added an answer on January 11, 2022 at 9:21 am

    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 dataframe
    np.random.seed(100)
    credit_card = pd.DataFrame(np.random.randint(10, size=(5,5)), columns=list(‘ABCDE’))
    print (credit_card)
    A B C D E
    0 8 8 3 7 7
    1 0 4 2 5 2
    2 2 2 1 0 8
    3 4 0 9 6 2
    4 4 1 5 3 4

    var1 = credit_card.var()
    print (var1)
    A 8.8
    B 10.0
    C 10.0
    D 7.7
    E 7.8
    dtype: float64

    var2 = credit_card.var(axis=1)
    print (var2)
    0 4.3
    1 3.8
    2 9.8
    3 12.2
    4 2.3
    dtype: 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.04
    B 8.00
    C 8.00
    D 6.16
    E 6.24
    dtype: float64

    var2 = credit_card.var(ddof=0, axis=1)
    print (var2)
    0 3.44
    1 3.04
    2 7.84
    3 9.76
    4 1.84
    dtype: float64

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 4k
  • Best Answers 0
  • Users 3
  • Popular
  • Answers
  • Alek Richter

    Make MS Word document look like it has been typeset ...

    • 2 Answers
  • Alek Richter

    When does a process get SIGABRT (signal 6)?

    • 2 Answers
  • Alek Richter

    How do I add sockets to an item?

    • 2 Answers
  • Alek Richter
    Alek Richter added an answer Pandas DataFrame columns are Pandas Series when you pull them… January 13, 2022 at 2:21 pm
  • Alek Richter
    Alek Richter added an answer The handshake failure could have occurred due to various reasons:… January 13, 2022 at 2:19 pm
  • Alek Richter
    Alek Richter added an answer Mac OS X doesn't have apt-get. There is a package… January 13, 2022 at 2:18 pm

Top Members

Alek Richter

Alek Richter

  • 4k Questions
  • 1k Points
Enlightened
coinbaseprosupportnumber[Xsdwerfgtyujhnbgfderewqasdxz]

coinbaseprosupportnumber[Xsdwerfgtyujhnbgfderewqasdxz]

  • 2 Questions
  • 2 Points

Trending Tags

questin question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • New Questions
  • Trending Questions
  • Must read Questions
  • Hot Questions

© 2021 Passionable. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.