如何使用时间戳确定是白天还是黑夜

编程入门 行业动态 更新时间:2024-10-28 08:21:22
本文介绍了如何使用时间戳确定是白天还是黑夜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想从数据框中的时间戳列中查找白天还是晚上。时间戳列的值如下: 20:0,14:30,6:15,5:0,4:0等

I want to find out whether it is day or night from the "timestamp" column in my data frame. The time stamp columns have values as follows: 20:0 , 14:30, 6:15, 5:0, 4:0 etc.

I使用了for循环,但它是日夜随机产生的。

I used a for loop but it randomly generated day and night.

for x in data['timestamp']: if x> '12:00': print('Day') else: print('Night')

我想在我的时间戳列旁边添加一列,当时间戳在6:00 am到18:00之间时,列的值为 Day;当时间戳为0时,列的值为 Night在18:01到5:59上午之间。

I want a column beside my timestamp column which has values as "Day" whenever the timestamp is between 6:00am to 18:00 and "Night" when the timestamp is between 18:01 to 5:59 am.

推荐答案

timestamp = ['6:00', '18:00', '18:01', '5:59'] for time in timestamp: hourMin = time.split(":") hour = int(hourMin[0]) mint = int(hourMin[1]) if hour>= 6 and hour <= 18: if(hour == 18): if(mint > 0): print("Night\n") else: print("Day\n") else: print("Day\n") else: print("Night\n")

更多推荐

如何使用时间戳确定是白天还是黑夜

本文发布于:2023-10-28 08:55:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536153.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   黑夜   白天   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!