# TypeError: cannot do label indexing on <class 'pandas.core.indexes.base.Index'> with these indexers [0] of <type 'int'>
printdf.iloc[0]
>>>
00
11
22
33
Name: a, dtype: int32
printdf.iloc['a'] # TypeError: cannot do positional indexing on <class 'pandas.core.indexes.base.Index'> with these indexers [a] of <type 'str'>
printdf.loc['a'] # 正确
>>>
00
11
22
33
Name: a, dtype: int32
同样地,把列标签[0, 1, 2, 3]改成['A', 'B, 'C', 'D'],则成这样了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
df.columns =['A','B','C','D']
printdf
>>>
A B C D
a 0123
b 4567
c 891011
printdf.loc[:,'A']
>>>
a 0
b 4
c 8
Name: A, dtype: int32
printdf.iloc[:,'A'] # ValueError: Location based indexing can only have [integer, integer slice (START point is INCLUDED, END point is EXCLUDED), listlike of integers, boolean array] types