|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
在pandas里对Series的各个位置、标签上的数据的访问,
可以通过loc、iloc、at、iat来访问。
带i的一般是通过位置相关得到数据,不带i的通过标签label来获得对应数据
这里的loc、iloc等不是函数,可以理解为index的属性。
- import pandas as pd
- import numpy as np
- val = np.array([2, 4, 5, 6])
- ii = range(10, 14)
- s0 = pd.Series(val)
- s1 = pd.Series(val, index=ii)
- idx = "hello the cruel world".split()
- t = pd.Series(val, index=idx)
- print("s0", "*" * 11)
- print(s0.iloc[0])
- print(s0.iat[3])
- print(s0.loc[0])
- print(s0.at[3])
- print("s2", "*" * 11)
- print(s1.iloc[1])
- print(s1.iat[2])
- print(s1.loc[11])
- print(s1.at[12])
- #print s1.iloc[11]#wrong
- #print s1.iat[12]
- #print s1.loc[1] #wrong
- #print s1.at[2]
- print ("t", "*" * 12)
- print(t.iloc[0])
- print (t.iat[2])
- print (t.loc["hello"])
- print (t.at["cruel"])
复制代码
输出结果:
s0 ***********
2
6
2
6
s2 ***********
4
5
4
5
t ************
2
5
2
5
|
|