AttributeError:'DataFrame'对象没有属性'allah1__27' [英] AttributeError: 'DataFrame' object has no attribute 'allah1__27'

查看:159
本文介绍了AttributeError:'DataFrame'对象没有属性'allah1__27'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解决这个问题,我很确定代码是正确的,但是它总是让我遇到相同的错误.

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

我已经尝试过了:

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'

我错过了什么吗?

推荐答案

第一个错误:isoformat方法来自datetime,这是datetime的方法.

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

您应该:

import datetime datetime.datetime.isoformat

import datetime datetime.datetime.isoformat

或者:

from datetime import datetime as datet datet.isoformat

from datetime import datetime as datet datet.isoformat

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

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

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

这篇关于AttributeError:'DataFrame'对象没有属性'allah1__27'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆