我分析了一个数据文件,该文件的second元素为julian
日期格式。在
array([(1957, 1, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999),
(1957, 13, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999)],
dtype=[('year', '<i4'), ('julian_date', '<i4'), ('1', '<i4'), ('2', '<i4'), ('3', '<i4'), ('4', '<i4'), ('5', '<i4'), ('6', '<i4'), ('7', '<i4'), ('8', '<i4'), ('9', '<i4'), ('10', '<i4'), ('11', '<i4'), ('12', '<i4')])
我只想将julian
日期转换为月份,以便可视化我的数据。在
我知道如何使用julian_date
元素执行简单的操作,例如:
我知道我可以使用datetime
函数进行转换:
datetime.date(1956, 1, 1) + datetime.timedelta(121 - 1)
返回datetime.date(1956, 4, 30)
,其中4是月份号
但是,我不知道如何将此应用于我的数据。我对python
和编程都是新手,如果有任何帮助,我将不胜感激。在
好吧。我想我已经接近.month
方法了。当我手动输入year
和julian_date
时:
x = datetime.date(1957, 1, 1) + datetime.timedelta(1 - 1)
galveston['julian_date'] = x.month
它将元素更改为相应的月份:
array([(1957, 1, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999),(1957, 1, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999)],dtype=[('year', '<i4'), ('julian_date', '<i4'), ('1', '<i4'), ('2', '<i4'), ('3', '<i4'), ('4', '<i4'), ('5', '<i4'), ('6', '<i4'), ('7', '<i4'), ('8', '<i4'), ('9', '<i4'), ('10', '<i4'), ('11', '<i4'), ('12', '<i4')])
但是,他们都收到相同的月价值,这不是我需要做的。当我试图像这样修改函数时(顺便说一句,这可能是完全错误的):
x = datetime.date('year', 1, 1) + datetime.timedelta('julian_date' - 1)
galveston['julian_date'] = x.month
我有个错误。在
我想我找到了自己问题的答案。我使用pandas库将一年中的日期转换为
datetime64
,然后我使用了.month
方法,正如{a1}所建议的那样。在相关问题 更多 >
编程相关推荐