pandas中的Series可使用字符串型作为索引
import pandas as pd
import numpy as np
from pandas import Series
price=np.linspace(10,50,5,dtype=np.int32)
#用numpy中的linspace在区间【10,50】平均生成五个数,类型为numpy中的int32型
series_fruit=Series(price,index=mlist)
#创建Series,指定mlist作为索引
series_fruit
按照索引0,1,2,3....切片
series_fruit[1:4]
按照mlist切片 ,‘pinapple’到'peach’
series_fruit['pineapple':'peach']
#Index(['orange', 'pineapple', 'blueberry', 'pear', 'peach'], dtype='object'
最后
以上就是热心西牛最近收集整理的关于python中的Series索引的全部内容,更多相关python中内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复