pandas series序列转化为星期几的实例

yipeiwu_com6年前Python基础

series序列中每个元素都是带有日期形式的字符串,需要将其转化为一个同等大小的series,且其中每个元素都是星期几。

1)将Series转化为datetime格式;

2)将Series中每个元素转化为星期;

time_list = ["2017-05-10 17:19:19", "2017-05-11 17:19:20", "2017-05-12 17:19:20", "2017-05-13 17:19:20"] 
time_ser = pd.Series(time_list) 
time_ser = pd.to_datetime(time_ser) 
 
for i in time_ser: 
  print(i.weekday()) 

以上这篇pandas series序列转化为星期几的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python3.2中的字符串函数学习总结

Sequence Types sequence类型有六种:strings, byte sequences (bytes objects), byte arrays(bytearray o...

python字符类型的一些方法小结

int 数字类型 class int(object): """ int(x=0) -> int or long int(x, base=10) -> int...

python获取指定日期范围内的每一天,每个月,每季度的方法

1.获取所有天,返回一个列表: def getBetweenDay(begin_date): date_list = [] begin_date = datetime.dat...

python中pass语句用法实例分析

本文实例讲述了python中pass语句用法。分享给大家供大家参考。具体分析如下: 1、空语句 do nothing 2、保证格式完整 3、保证语义完整 4、以if语句为例: C/C++...

python 获取毫秒数,计算调用时长的方法

如题:在python的函数调用中需要记录时间,下面是记录毫秒时间的方法。 import datetime import time t1 = datetime.datetime.now...