pandas 1 - Series序列创建( tcy)
发布日期:2021-06-29 14:47:57 浏览次数:3 分类:技术文章

本文共 892 字,大约阅读时间需要 2 分钟。

创建Series      2018/12/2 

函数

Series(data=None, index=None, dtype=None, name=None, copy=False, fastpath=False)参数:data数据:ndarray,list,dict,标量,constants;index索引值: pandas支持非唯一索引值

实例

#实例1:创建空序列s = pd.Series()#Series([], dtype: float64)#实例2:ndarray创建s = pd.Series(np.arange(1,4), index=['a', 'b', 'c']) # 行标签a,b,c 索引长度=数据长度# s = pd.Series(np.arange(1,4)) 行标签0,1,2 dtype: int32;#实例3:list,tuple 创建s = pd.Series([1,2,np.nan,4],index=[1,2,3,4])#实例4:dict创建 (键作为索引名)d = {'a':1,'b':2,'c':3} # 索引优先,缺少元素用NaNs=pd.Series(d) # 行标签a,b,c dtype: int64s=pd.Series(d,index=['b','c','d']) # 行标签b,c,d dtype: float64#实例5:标量创建-必须提供索引index=pd.date_range('2018-12-02',periods=3)s=pd.Series(5.,index=index) # 行标签日期 dtype: float64#实例6:Series创建pd.Series(s.index+10)# 实例5结果          实例6结果# 2018-12-02 5.0    0 2018-12-12# 2018-12-03 5.0    1 2018-12-13# 2018-12-04 5.0    2 2018-12-14# Freq: D, dtype: float64 dtype: datetime64[ns]

转载地址:https://chunyou.blog.csdn.net/article/details/84670423 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:pandas 学习汇总2 - 数据帧DataFrame创建(12种方法)( tcy)
下一篇:numpy 学习汇总45 - 数组选择设置(11种方法)( 初步学习 tcy)

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月15日 22时34分43秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章