|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
# 常用的方法还是list来提供数据和index、label比较好,
# 原因是字典不能有重复的key而列表是允许有重复的。
- import pandas as pd
- s = pd.Series({'a':100,'b':200,'e':300}
- print(s)
- i = ['a','b','c','a']
- v = [2,4,5,7]
- t = pd.Series(v,index=i,name='col_name')
- print(t)
复制代码
执行结果:
# print s
a 100
b 200
e 300
dtype: int64
# print t
a 2
c 4
d 5
a 7
Name: col_name, dtype: int64
由于Series的label是允许重复的,上边的例子的t里的标签为'a'对应两条数据,但位置信息却不同。
继续输入以下代码:
- print("t['a']\n", t["a"])
- print('t[0]', t[0])
- print('t[3]', t[3])
复制代码
输出结果:
Name: col_name, dtype: int64
t['a']
a 2
a 7
Name: col_name, dtype: int64
t[0] 2
t[3] 7
|
-
Series的创建
|