pandas 与朱利安·戴(Julian Day)的约会时间 [英] Pandas datetime with Julian Day

查看:89
本文介绍了 pandas 与朱利安·戴(Julian Day)的约会时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试搜索此内容,但感到惊讶的是我找不到任何东西.我们使用朱利安日"一词来指年份,与月份无关(即2月1日将是朱利安日32).我不知道这是否是一个地区性术语,也许也不知道为什么我找不到任何答案.

I tried searching for this and was surprised I couldn't find anything. We use the term 'Julian Day' to refer to the day of the year irrespective of month (i.e. February 1st would be julian day 32). I don't know if this is a regional term and maybe why I can't find any answers.

基本上我有两个文件.一个具有年,月,日,小时的标准日期格式.另一个有年,朱利安日,小时.我正在尝试使用pandas DataFrame函数对齐它们,但不知道该如何处理丢失的月份数据.熊猫能够将其本地转换吗?

Basically I have two files. One has a standard date format with year, month, day, hour. The other has year, julian day, hour. I am trying to align them using pandas DataFrame function and don't know what to do about the missing month data. Is Pandas able to convert this natively?

我正在使用python 3.3和最新版本的Pandas.

I am using python 3.3 and the newest version of Pandas.

谢谢!

推荐答案

在读取儒略日期文件时,您只需要提供自定义日期解析功能即可.这是一个示例:

When you read in the Julian date file, you simply need to provide a custom date parsing function. Here's an examples:

import datetime
from io import StringIO
import pandas

datafile = StringIO("""\
jday,value
2013-01,1
2013-02,2
2013-100,8
2013-200,9
""")

dateparser = lambda x: datetime.datetime.strptime(x, '%Y-%j')
df = pandas.read_csv(datafile, parse_dates=True, date_parser=dateparser, index_col=[0])

给出df

            value
jday             
2013-01-01      1
2013-01-02      2
2013-04-10      8
2013-07-19      9

我将此页面标记为书签,并方便处理非常规"日期解析需求,例如这些. (我实际上并不认为朱利安时代很奇怪-我们一直在水力模型中使用它们)

I keep this page bookmarked and handy for "unconventional" date parsing needs such as these. (I don't actually think julian days are weird -- we use them all the time in hydraulic modeling)

这篇关于 pandas 与朱利安·戴(Julian Day)的约会时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆