社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

“datetime.datetime”在python中没有“datetime”属性

Maram Mubarak • 5 年前 • 1794 次点击  

嗨,我有很长的代码,如果你想检查的话,告诉我,所以我试着解决这个问题,我很确定代码是对的,但它总是让我犯同样的错误,我尽一切努力解决它,但它是一样的,我检查了属性是否丢失,但它在那里,我不知道我做错了什么 这是我的密码

import pandas as pd
import geopandas as gpd
import time
import pickle
import os
import numpy as np
import xgboost
import pytz
import arcgis
#
#plotting
#'''
from IPython.display import HTML, display
import datashader as ds
from datashader import transfer_functions as tf
from datashader.colors import colormap_select, Greys9, Hot, viridis, inferno
#'''

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
from matplotlib.ticker import NullFormatter
import matplotlib as mpl
mpl.rc('xtick', color='k')
mpl.rc('ytick', color='k')
%matplotlib inline
#'''
import datetime
from pandas import Series
from datetime import datetime, timedelta
import time
from datetime import datetime, date, time, timedelta


predTimest = pd.date_range('01/06/2017', periods=7*24, freq='H',tz='US/Mountain')
predTimest
n [28]:


predTimest


Out[28]:
DatetimeIndex(['2017-01-06 00:00:00-07:00', '2017-01-06 01:00:00-07:00',
               '2017-01-06 02:00:00-07:00', '2017-01-06 03:00:00-07:00',
               '2017-01-06 04:00:00-07:00', '2017-01-06 05:00:00-07:00',
               '2017-01-06 06:00:00-07:00', '2017-01-06 07:00:00-07:00',
               '2017-01-06 08:00:00-07:00', '2017-01-06 09:00:00-07:00',
               ...
               '2017-01-12 14:00:00-07:00', '2017-01-12 15:00:00-07:00',
               '2017-01-12 16:00:00-07:00', '2017-01-12 17:00:00-07:00',
               '2017-01-12 18:00:00-07:00', '2017-01-12 19:00:00-07:00',
               '2017-01-12 20:00:00-07:00', '2017-01-12 21:00:00-07:00',
               '2017-01-12 22:00:00-07:00', '2017-01-12 23:00:00-07:00'],
              dtype='datetime64[ns, US/Mountain]', length=168, freq='H')
prediction_time = predTimest[15]
test_df = shapefile.copy()
test_df['timestamp'] = prediction_time
test_df['allah1__27'] = shapefile.allah1__27.astype('int64')
test_df['hour'] = prediction_time.hour
test_df['weekday'] = prediction_time.weekday()
test_df['month'] = prediction_time.month
def add_join_key(df):
    df['join_key'] = df.allah1__27.map(int).map(str)+df.timestamp.map(datetime.datetime.isoformat)
    df = df.set_index('join_key')
    return df
weath_df = wdf.loc[prediction_time]
test_df = add_join_key(test_df)
weath_df = add_join_key(weath_df.reset_index())

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-65-4714b1ff587e> in <module>
----> 1 test_df = add_join_key(test_df)
      2 weath_df = add_join_key(weath_df.reset_index())

<ipython-input-63-1a4e6a6f2c07> in add_join_key(df)
      1 def add_join_key(df):
----> 2     df['join_key'] = df.allah1__27.map(int).map(str)+df.timestamp.map(datetime.datetime.isoformat)
      3     df = df.set_index('join_key')
      4     return df

AttributeError: type object 'datetime.datetime' has no attribute 'datetime'
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/55581
 
1794 次点击  
文章 [ 2 ]  |  最新文章 5 年前