Home > other >  AttributeError: 'DataFrame' object has no attribute '_loc'. Did you mean: '
AttributeError: 'DataFrame' object has no attribute '_loc'. Did you mean: '

Time:12-24

Unfortunately this code doesn't work for me in PyCharm:

`

import pandas as pd

data = {'Name': ['Jai', 'Princi', 'Gaurav', 'Anuj'], 'Age': [27, 24, 22, 32],
        'Address': ['Delhi', 'Kanpur', 'Allahabad', 'Kannauj'], 'Qualification': ['Msc', 'MA', 'MCA', 'Phd']}

df = pd.DataFrame(data)

df.loc[0, :]

`

Could you please help?

Tried to update Pandas

CodePudding user response:

Try:

print(df.loc[0, :])

instead of

df.loc[0, :]

although it working fine on my pycharm..

enter image description here

CodePudding user response:

df = pd.DataFrame([[1, 2], [4, 5], [7, 8]],
        index=['cobra', 'viper', 'sidewinder'],
        columns=['max_speed', 'shield'])
print(df.loc[['viper', 'sidewinder']])

But this one doesn't work as well.

  • Related