Need another []:
df= a[['Rank', 'Country']]
what is same as, but it is less typing:
df = a.loc[:, ['Rank', 'Country']]
Sample:
a = pd.DataFrame({'Rank':[1,2,3],
'Country':[4,5,6],
'C':[7,8,9]})
print (a)
C Country Rank
0 7 4 1
1 8 5 2
2 9 6 3
df = a.loc[:, ['Rank', 'Country']]
print (df)
Rank Country
0 1 4
1 2 5
2 3 6
df = a[['Rank', 'Country']]
print (df)
Rank Country
0 1 4
1 2 5
2 3 6
You can also check docs:
You can pass a list of columns to [] to select columns in that order.
Also for select column to one column DataFrame use [] too:
df = a[['Rank']]
print (df)
Rank
0 1
1 2
2 3
but for Series:
s = a['Rank']
print (s)
0 1
1 2
2 3
Name: Rank, dtype: int64