简体   繁体   English

是否有一种简单的方法可以在 Python 中绘制和操作持续时间(小时/分钟/秒)数据? 非日期时间数据

[英]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.

相关问题 有没有办法在 Python 中按时间格式(小时:分钟:秒)从 excel 文件读取的数据执行数学运算(平均值和总和)? - Is there a way to perform math operations (average and sum) in Python on time formatted (hours:minutes:seconds) DATA read from an excel file? 以日期时间为索引绘制数据框,仅在 python 的 x 轴上显示小时、分钟和秒 - plot dataframe with datetime as index and only display hours, minutes, and seconds on x-axis in python Python-将时间转换为小时和分钟,而不是秒 - Python - convert time to hours and minutes, not seconds Python 以天、小时、分钟、秒表示的经过时间 - Python Elapsed Time as Days, Hours, Minutes, Seconds 如何在Python / Django中将此持续时间转换为天/小时/分钟/秒? - How to convert this duration into days/hours/minutes/seconds in Python/Django? Python datetime.strmp值错误,同时从CSV文件获取以小时,分钟和秒为单位的时间 - Python datetime.strmp Value Error while getting time in hours minutes and seconds from CSV File Python时间格式为=> [天:小时:分钟:秒]至秒 - Python time in format => [days:hours:minutes:seconds] to seconds 在Pandas中显示Python没有时分秒的日期时间 - Display Python datetime without hours, minutes and seconds in Pandas 如何仅获取没有小时分钟和秒的日期时间 python pandas - How to only get datetime without hours minutes and seconds python pandas Python:有没有办法用写为“小时”:“分钟”:“秒”:“毫秒”的值减去日期时间对象 - Python: Is there a way to subtract date time objects with the values written as “hours”:“minutes”:“seconds”:“milliseconds”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM