I am fairly new to python and would like to calculate sun's position (azimuth and zenith angle) from a datetime column of a dataframe.
I found Astral module for this task and also made some correct calculations from it using the individual timestamps. But when I try to process the whole datetime column, I get an error.
I also tried to localize the dataframe (datetime column) to a specific timezone, but the error remains the same.
Help appreciated.
Here is the code:
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")
The output looks like:
0 2015-02-04 09:10:21
1 2016-03-05 11:30:25
dtype: datetime64[ns]
Azimuth calculation:
print(Astral().solar_azimuth(d1, 52.52, -13.40))
Error:
---------------------------------------------------------------------------
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'