AttributeError: DataFrame object has no attribute allah1__27

2024/11/18 1:41:29

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 datettest_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?

Answer

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://en.xdnf.cn/q/120133.html

Related Q&A

How to convert csv to dictionary of dictionaries in python?

I have a CSV file shown below.I need to convert CSV to dictionary of dictionaries using python.userId movieId rating 1 16 4 1 24 1.5 2 32 4 2 47 4 2 …

Mo Money- Making an algorithm to solve two variable algebra problems

A cash drawer contains 160 bills, all 10s and 50s. The total value ofthe 10s and 50s is $1,760.How many of each type of bill are in the drawer? You can figure thisout by trial and error (or by doing a…

How to explode Python Pandas Dataframe and merge strings from other dataframe?

Dataframe1 has a lot of rows and columns of data. One column is Text. Certain rows in Text column have strings and some strings include within the strings this {ExplodeEList2} How to explode (expand) t…

Creating a new column with numbers in Pandas to group with a column with existing numbers

Good day, I have a column from a data frame here:A231011 22My objective is to create a new column and associate the numbers like this:A file_number 23 8 10 6 11 6 22 8As…

How to get PDF file from the binary data of SoftLayers quote?

I got the binary data by "getPdf" method of SoftLayers API.Ref. BillingSoftLayer_Billing_Order_Quote::getPdf | SoftLayer Development Network - http://sldn.softlayer.com/reference/services/Sof…

How to list of elements and use those elements as a header of pandas dataframe?

I have a list with some elements. For example: list= [name, phone_number,age,gender] I want to use these elements as a header or column name in a pandas dataframe. I would really appreciate your ideas.…

Averaging Filter using python

I am new in python and trying apply averaging filter on image as the way i understand averaging concept summing up the neighboring elements including itself and divide it by number of elementstechnique…

Click on Show more deals in webpage with Selenium

Id like to click on every Show 10 more deals on the following page: "https://www.uswitch.com/broadband/compare/deals_and_offers/" but it does not seem to work. Im stuck having the following e…

In Matplotlib, what axis attribute specifies the spacing between ticks? [duplicate]

This question already has answers here:Changing the tick frequency on the x or y axis(15 answers)Closed 6 years ago.When generating a Matplotlib line or scatter plot, what axis attribute specifies the …

How can I make a simple calculator in python 3?

Im making this calculator using python 3, and this is what I have so far:print("Welcome to Calculator!")class Calculator:def addition(self,x,y):added = x + yreturn addeddef subtraction(self,x…