我是python的新手,我想从数据帧的datetime列计算太阳的位置(方位角和天顶角)
我为这项任务找到了Astral模块,并使用各个时间戳进行了一些正确的计算。 但是当我试图处理整个datetime列时,我得到了一个错误
我还尝试将dataframe(datetime列)本地化为特定的时区,但错误保持不变
谢谢你的帮助
代码如下:
import datetime
from datetime import datetime
import pytz
pytz.all_timezones
from astral import Astral
d1=pd.to_datetime(d1)
d1=d1.dt.tz_localize("Europe/Berlin")
输出如下所示:
0 2015-02-04 09:10:21
1 2016-03-05 11:30:25
dtype: datetime64[ns]
方位角计算:
print(Astral().solar_azimuth(d1, 52.52, -13.40))
错误:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-95-2a14f69465f4> in <module>
----> 1 print(Astral().solar_azimuth(d1, 52.52, -13.40))
~\Anaconda3\lib\site-packages\astral.py in solar_azimuth(self, dateandtime, latitude, longitude)
2276 latitude = -89.8
2277
-> 2278 if dateandtime.tzinfo is None:
2279 zone = 0
2280 utc_datetime = dateandtime
~\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
5137 if self._info_axis._can_hold_identifiers_and_holds_name(name):
5138 return self[name]
-> 5139 return object.__getattribute__(self, name)
5140
5141 def __setattr__(self, name: str, value) -> None:
AttributeError: 'Series' object has no attribute 'tzinfo'
不确定您的代码示例是如何工作的,但基本上,您可以
apply
将solar_azimuth
函数转换为pandas.Series
函数,例如请注意,您也可以在没有熊猫的情况下执行此操作,例如
相关问题 更多 >
编程相关推荐