Pandas数据结构
Series数据结构
创建Series
传入列表
import pandas as pd
S1 = pd.Series(['a','b','c','d'])
S1
>>>
0 a
1 b
2 c
3 d
dtype: object
指定索引
index参数自定义索引
import pandas as pd
S1 = pd.Series(['a','b','c','d'],index = [1,2,3,4])
S1
>>>
1 a
2 b
3 c
4 d
dtype: object
传入字典
import pandas as pd
S1 = pd.Series({'a':1,'b':2,'c':3,'d':4})
S1
>>>
a 1
b 2
c 3
d 4
dtype: int64
- key 为数据标签
- value 为数据值
获取Series行、列索引
index获取Series索引
S1.index
>>>
Index(['a', 'b', 'c', 'd&#