Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'>
like image 756
Neeraj Hanumante Avatar asked Jul 18 '26 20:07

Neeraj Hanumante


1 Answers

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

like image 169
Nand0san Avatar answered Jul 21 '26 09:07

Nand0san



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!