Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
loc error
#1
Hi ,

While trying to restrict data set to UK cases only . I have applied the following code .
*************************************************************************
df1 = df1.loc[df1['Country'] == 'United Kingdom']
*************************************************************************
error :
AttributeError: 'list' object has no attribute 'loc'

Can anyone please suggest, why is this happening ?
Reply
#2
Error:
>>> [].loc Traceback (most recent call last):   File "<string>", line 301, in runcode   File "<interactive input>", line 1, in <module> AttributeError: 'list' object has no attribute 'loc'
df1 is a list object,can try to access it like this.
df1 = df1[0].loc[df1['Country'] == 'United Kingdom']
If not work you have to look closer at list(df1).
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020