700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > python_pandas模块中series函数使用

python_pandas模块中series函数使用

时间:2019-12-04 05:54:23

相关推荐

python_pandas模块中series函数使用

Series

功能:数组前面自动添加序号index

>>> import pandas as pd# 导入pandas模块s = pd.Series([1,2,3,4])s> 0 11 22 33 4dtype: int64>>> s.index> RangeIndex(start=0, stop=4, step=1)

更改前面序号index

>>> s2 = pd.Series([1,2,3,4],index = ['a','b','c','d'])s> a 1b 2c 3d 4dtype: int64

索引方法

>>> s1[1]> 2>>> s2['a']> 1# 多值索引>>> s2[['a','c']]# 最外面[]代表索引,里面[]索引的列表> a 1c 3dtype: int64

增加或者更改列表内容

>>> s2['m'] = 10s2> a1b2c3d4m 10dtype: int64#更改序号>>> d = {'mm':'aox','oo':'box','pp':'dox'}s3 = pd.Series(d,index = ['mm','xx','pp','kk'])s3> mm aoxxx NaNpp doxkk NaN# 即使序号增多,series一样可以识别,显示空值dtype: object

数值类型转换【series列表只能显示一种数据类型,list列表 可以多类型显示】

>>> s2.astype('str')> a 1b 2c 3d 4dtype: object#int64改成了boject

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。