Python 比较'时出错;int';键入至';numpy.int32';类型

Python 比较'时出错;int';键入至';numpy.int32';类型,python,pandas,numpy,datetime,typeerror,Python,Pandas,Numpy,Datetime,Typeerror,我正在尝试根据其他两列的值在pandas dataframe中创建一个新列。我首先使用包含经度的列来计算该位置的时间: current_weather['Hour'] = np.where(round(current_weather['Longitude']/15,0) < 0, (round(24 + current_weather['Longitude']/15,0).astype(int)),

我正在尝试根据其他两列的值在pandas dataframe中创建一个新列。我首先使用包含经度的列来计算该位置的时间:

current_weather['Hour'] = np.where(round(current_weather['Longitude']/15,0) < 0,
                               (round(24 + current_weather['Longitude']/15,0).astype(int)), 
                               (round(current_weather['Longitude']/15,0).astype(int)))
当前天气['Hour']=np.where(圆形(当前天气['Longitude']/15,0)<0,
(圆形(24+当前天气['经度]/15,0).aType(int)),
(圆形(当前天气[经度]/15,0.astype(int)))
此列中的值为numpy.int32

然后,我将通过比较小时列和日出和日落(作为整数的unix时间戳),创建一个列来标记是白天还是黑夜

current_weather['Day/Night'] = np.where((current_weather['Hour'] >= datetime.datetime.fromtimestamp(current_weather['Sunrise']).hour) & (current_weather['Hour'] <= datetime.datetime.fromtimestamp(current_weather['Sunset']).hour),
                                    'Day','Night')
current_weather['Day/Night']=np.where((current_weather['Hour']>=datetime.datetime.fromtimstamp(current_weather['Sunrise'].Hour)&(current_weather['Hour']您使用不正确。它不接受序列作为输入

>>> import datetime
>>> import time
>>> timestamp = time.time()
>>> datetime.datetime.fromtimestamp(timestamp)
datetime.datetime(2018, 7, 22, 20, 10, 56, 241211)
>>> import pandas as pd
>>> series = pd.Series([1,5,7])
>>> datetime.datetime.fromtimestamp(series)
...
TypeError: cannot convert the series to <class 'int'>
>>>
现在,您可以使用从这些时间戳中提取小时


您是否尝试将astype(int)转换为int“
&
几乎肯定不是您想要的。我在上面计算“小时”的代码单元格中这样做了,但返回的是numpy.int32还有一件事,当我用静态整数7和19替换变量Sunrise和Sunset对象时,我的代码似乎工作正常。@IgnacioVazquez Abrams为什么说&不是我想要的?谢谢。”@作为输入,我还没能回到这个项目上来,但我会在这个周末回来。
>>> import datetime
>>> import time
>>> timestamp = time.time()
>>> datetime.datetime.fromtimestamp(timestamp)
datetime.datetime(2018, 7, 22, 20, 10, 56, 241211)
>>> import pandas as pd
>>> series = pd.Series([1,5,7])
>>> datetime.datetime.fromtimestamp(series)
...
TypeError: cannot convert the series to <class 'int'>
>>>
>>> import pandas as pd
>>> sunset = pd.to_datetime(pd.Series([1349720105, 1349806505, 1349892905,]), unit='s')
>>> sunset
0   2012-10-08 18:15:05
1   2012-10-09 18:15:05
2   2012-10-10 18:15:05
dtype: datetime64[ns]
>>> 
>>> sunset.dt.hour
0    18
1    18
2    18
dtype: int64
>>> hour = pd.Series([6, 12, 20]) # assume hour you have
>>> hour > sunset.dt.hour
0    False
1    False
2     True
dtype: bool
>>>