![](/img/trans.png)
[英]Python Firebase How to check whether a file exists on firebase storage
[英]python - how to check whether some given date exists in netcdf file
我从netcdf文件中读取了时间步长:
timesteps = ncfile.variables['time']
现在,我想知道该列表中是否存在某个给定的日期(例如6月23日)。 如果是这样,我想忽略它。 netcdf文件包含任意日期。
我不知道如何在python中执行此操作。 我是python的新手,我在python中的编程经验已在https://xkcd.com/1513/中得到了最好的描述,但是我没有时间去学习课程,因此对您的帮助将不胜感激。
谢谢!
好的,这不是很好的样式,但可能会为您带来想要的东西。 假设您的时间是字符串,并且您确信纯字符串比较将对您有用,那么您可以执行以下操作:
timesteps = ncfile.variables['time']
dates_to_skip = set(['June 23th', 'May 28th', 'April 1st'])
filtered_timesteps = filter(lambda t: t not in dates_to_skip, timesteps)
更好的方法是解析时间步长时间(字符串或数字),然后转换为datetime.date对象,并与您在代码中创建的datetime.date对象进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.