Python Forum

Full Version: loc error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 ?
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).