Python-Pandas入门

1.在对DataFrame进行索引的时候,引用标签字段作为索引,是包含的,而引用数字作为索引,是不包含的。比如:
data=pd.DataFrame(np.arange(16).reshape(4,4),index=['Ohio','Colorado','Utah','New York'],columns=['one','two','three','four'])
>>> data
one two three four
Ohio 0 1 2 3
Colorado 4 5 6 7
Utah 8 9 10 11
New York 12 13 14 15
 
data.ix[:'Utah',:2]
one two
Ohio 0 1
Colorado 4 5
Utah 8 9
(引用列数为:one,two,2列不包含)
 
data.ix[:'Utah',:'two']
one two
Ohio 0 1
Colorado 4 5
Utah 8 9
(引用列数为:one,two,two列被包含)

1 个评论

Good finding!

要回复文章请先登录注册