[英]Is there an easy way to plot and manipulate time duration (hours/minutes/seconds) data in Python? NOT datetime data
I'm working with some video game speedrunning (basically, races where people try to beat a game as fast as they can) data, and I have many different run timings in HH:MM:SS format.我正在处理一些视频游戏速度运行(基本上,人们试图以尽可能快的速度击败游戏的比赛)数据,并且我有许多不同的 HH:MM:SS 格式的运行时间。 I know it's possible to convert to seconds, but I want to keep in this format for the purposes of making the axes on any graphs easy to read.
我知道可以转换为秒,但我想保持这种格式,以使任何图形上的轴易于阅读。
I have all the data in a data frame already and tried converting the timing data to datetime format, with format = '%H:%M:%S', but it just uses this as the time on 1900-01-01.我已经拥有数据框中的所有数据,并尝试将计时数据转换为日期时间格式,格式 = '%H:%M:%S',但它只是将其用作 1900-01-01 的时间。
data=[['Aggy','01:02:32'], ['Kirby','01:04:54'],['Sally','01:06:04']]
df=pd.DataFrame(data, columns=['Runner','Time'])
df['Time']=pd.to_datetime(df['Time'], format='%H:%M:%S')
I thought specifying the format to be just hours/minutes/seconds would strip away any date, but when I print out the header of my dataframe, it says that the time data is now 1900-01-01 01:02:32, as an example.我认为将格式指定为仅小时/分钟/秒会删除任何日期,但是当我打印出我的数据帧的标题时,它说时间数据现在是 1900-01-01 01:02:32,如一个例子。 1:02:32 AM on January 1st, 1900. I want Python to recognize the 1:02:32 as a duration of time, not a datetime format.
1900 年 1 月 1 日凌晨 1:02:32。我希望 Python 将 1:02:32 识别为持续时间,而不是日期时间格式。 What's the best way to go about this?
解决这个问题的最佳方法是什么?
The format
argument defines the format of the input date, not the format of the resulting datetime object ( reference ). format
参数定义输入日期的格式,而不是生成的日期时间对象 ( reference ) 的格式。
For your needs you can either use the H:m:s part of the datetime, or use the to_timedelta method.根据您的需要,您可以使用日期时间的H:m:s部分,或使用to_timedelta方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.