【问题标题】:AttributeError: 'DataFrame' object has no attribute 'allah1__27'AttributeError:“DataFrame”对象没有属性“allah1__27”
【发布时间】:2019-08-18 16:30:39
【问题描述】:

我正在尝试解决这个问题,我很确定代码是正确的,但它总是给我同样的错误。

我试过这个:

import datetime
from datetime import datetime as datet

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.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: module 'datetime' has no attribute 'isoformat'

我也试过了:

def add_join_key(df):
    df['join_key'] = df.allah1__27.map(int).map(str)+df.timestamp.map(datet.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: DataFrame' object has no attribute 'allah1__27'

我错过了什么吗?

【问题讨论】:

    标签: python datetime machine-learning arcpy


    【解决方案1】:

    对于第一个错误:方法 isoformat 来自 datetime,它是 datetime 的一个方法。

    你应该:

    import datetime datetime.datetime.isoformat

    或者:

    from datetime import datetime as datet datet.isoformat

    关于第二个错误: df 是一本字典,我想你应该叫它:

     df['join_key'] = df['allah1__27'].map(int).....
    

    【讨论】:

    • @leardoArnsGonzales 我使用了 datet.isoformat,我得到了 ValueError: cannot convert float NaN to integer
    • 你能在你使用它的地方显示代码吗?还是消息错误?它可能与您传递的值有关
    猜你喜欢
    • 1970-01-01
    • 2013-10-23
    • 2017-01-24
    • 2018-10-10
    • 2021-01-20
    • 2020-05-16
    • 2018-10-04
    • 2021-04-05
    • 2021-11-24
    相关资源
    最近更新 更多