Pandas dataframe: df.shape throws error 'TypeError: 'tuple' object is not callable'
Asked Answered
O

1

6

Background

I am trying to get shape of a dataframe. I read the data from from a csv file to a dataframe using pd.read_csv and then am trying ro get its dimensions.

Code

file_name = 'xxxxxx.csv'

with open(file_name, 'r') as f:
    metadata_location = [i for i, x in enumerate(f.readlines()) if 'Metadata' in x]

with open(file_name, 'r') as f:
    data = pd.read_csv(f, index_col=False, skipfooter=26)
print(data.shape())

Error

TypeError: 'tuple' object is not callable

How to resolve it???????

Other checks

print(type(data))
<class 'pandas.core.frame.DataFrame'>
Ovate answered 11/6, 2020 at 10:46 Comment(3)
simply call data = pd.read_csv(file_name, index_col=False, skipfooter=26) without openKaiulani
Same error again 'TypeError: 'tuple' object is not callable'Ovate
remove the () after shape. its an property not a class methodKaiulani
T
12

The error is because shape() throws error, the correct way is without parenthesis.

If you change:

print(data.shape())

For:

print(data.shape)

It will print the shape of data

Do you really need the second: with open... ? Pandas can load without the with open line

Technology answered 11/6, 2020 at 11:8 Comment(1)
I just were answering and saw your coment after, sorry for the confusion @luigigi, but I tried that and saw the error in my jupyter notebook when your comment was not posted yet, at least in my answer loaded page.Technology

© 2022 - 2024 — McMap. All rights reserved.