pandas 学习汇总5 - index 创建( tcy)
发布日期:2021-06-29 14:47:59 浏览次数:2 分类:技术文章

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

index 创建  2018/12/2

#1.pd.Indexi=pd.Index([1,2,3,4]) # (Int64Index([1, 2, 3, 4], dtype='int64')i=pd.Index(list('abcd')) # Index(['a','b','c','d'], dtype='object'))#2.pd.RangeIdex(start=None, stop=None, step=None)迭代器i=pd.RangeIndex(4) # RangeIndex(start=0, stop=4, step=1)[i1 for i1 in i] #[0, 1, 2, 3, 4]#3.pd.date_range(start=None, end=None, periods=None, freq=None)# freq:#Y年显示每年的最后一天;M显示每月的最后一天;D天;H小时;60S一分钟date=pd.date_range('2018-10-13',periods=3)# DatetimeIndex(['2018-10-14','2018-10-15','2018-10-16'],dtype='datetime64[ns]',freq='D')i_str=date.strftime('%Y-%m-%d %H:%M:%S')#将日期index变成字符串index# Index(['2018-10-14 00:00:00','2018-10-15 00:00:00','2018-10-16 00:00:00'],dtype='object')
#4.pd.DatetimeIndex(data=None, freq=None, start=None, end=None, periods=None, ...)  dt=pd.DatetimeIndex(['2018-10-14', '2018-10-15', '2018-10-16'])         # DatetimeIndex(['2018-10-14', '2018-10-15', '2018-10-16''], dtype='datetime64[ns]', freq=None)    s=pd.Series(data=np.arange(10,14),index=pd.date_range('2018-10-14',periods=4),dtype=np.float, name='Series-1')s.index  # DatetimeIndex(['2018-10-14', '2018-10-15', '2018-10-16'], dtype='datetime64[ns]', freq='D')s             # 2018-10-14    10.0             # 2018-10-15    11.0             # 2018-10-16    12.0             # Freq: D, Name: Series-1, dtype: float64

 

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

上一篇:pandas 6 - 索引切片选择( tcy)
下一篇:pandas 4 - 排序( tcy)

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月20日 13时33分19秒