AttributeError: 'DataFrame' object has no attribute 'allah1__27'

柔情痞子 提交于 2019-12-13 09:13:38

问题


I'm trying to solve this and I'm pretty sure the code is right but it keeps getting me the same Error.

I have tried this:

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())

And I get this Error:

AttributeError: module 'datetime' has no attribute 'isoformat'

Also I tried:

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())

And I get this Error:

AttributeError: DataFrame' object has no attribute 'allah1__27'

Did I miss something?


回答1:


For the first error: the method isoformat is from datetime that's a method of datetime.

You should:

import datetime datetime.datetime.isoformat

Or:

from datetime import datetime as datet datet.isoformat

As for the second error: df is a dictionary, i think you should call it:

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


来源:https://stackoverflow.com/questions/55388516/attributeerror-dataframe-object-has-no-attribute-allah1-27

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!