关于Pandas中的部分索引技巧

来源:互联网 发布:天下三男鬼墨捏脸数据 编辑:程序博客网 时间:2024/06/10 02:04

关于Pandas中的部分索引技巧

import pandas as pdimport 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))
ser1ser1.index=['a','b','c','d','e','f','g','h','i']ser1
a    0b    1c    2d    3e    4f    5g    6h    7i    8dtype: 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    61    72    8Name: c, dtype: int32
df1.loc['b']
0    31    42    5Name: 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 indexingSee the documentation here:http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated  """Entry point for launching an IPython kernel.0    31    42    5Name: b, dtype: int32
原创粉丝点击