(1)基本概念
单独的几列就是一个Series结构,几个Series结构共同构成DataFrame结构
cardtype = subway_info["card_type"] #单独提取出card_type列,这就是一个Series结构
print(type(cardtype))
(2):自定义Series结构
- ① 以on_station的值为Series结构新值,以card_type值为索引编号,建立一个新的Series结构
- 可以用新定义的索引编号输出信息
- 仍然可以用原来的索引编号来输出信息
代码:
series_card = subway_info["card_type"]
series_on = subway_info["on_station"]
cardtype = series_card.values
onstation = series_on.values
series_custom = Series(onstation, index=cardtype)
print(series_custom[[101, 102]]) #输出索引编号(即卡种号)为101和102的信息
print('---------------')
three_to_ten = series_custom[3:10]
print(three_to_ten) #输出原来索引编号3-10的信息
输出:
101 8.0
101 12.0
101 35.0
101 NaN
101 100.0
102 25.0
dtype: float64
---------------
101 35.0
101 NaN
7 11.0
7 55.0
7 NaN
7 37.0
7 17.0
7 90.0
dtype: float64