Neeraj Hanumante
Neeraj Hanumante

Reputation: 1684

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

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'>

Upvotes: 7

Views: 10426

Answers (1)

Nand0san
Nand0san

Reputation: 511

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

Upvotes: 13

Related Questions