关于Pandas中的部分索引技巧
import pandas as pd
import numpy as np
obj=np.arange(9).reshape(3,3)
obj
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
Series:
ser1=pd.Series(range(9))
ser1
ser1.index=['a','b','c','d','e','f','g','h','i']
ser1
a 0
b 1
c 2
d 3
e 4
f 5
g 6
h 7
i 8
dtype: int64
obj2=np.arange(9).reshape(3,3)
DataFrame:
df1=pd.DataFrame(obj2,columns=range(3),index=['a','b','c'])
# .ioc与.iloc 都用于行索引(index)
# .loc 标签索引
# .iloc 位置(index)索引
df1.iloc[2]
0 6
1 7
2 8
Name: c, dtype: int32
df1.loc['b']
0 3
1 4
2 5
Name: b, dtype: int32
df1.ix[1]
C:\Python\lib\site-packages\ipykernel_launcher.py:1: DeprecationWarning:
.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing
See the documentation here:
http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated
"""Entry point for launching an IPython kernel.
0 3
1 4
2 5
Name: b, dtype: int32