'Datetimeproperties' Object Has No Attribute 'Isocalendar'

I have a dataset with trips and their respective start and end times. For analyzing that data I want to add the month, week, day and hour of the start time in my dataframe.

Here is that part of my script:

    data["start_time"] = pd.to_datetime(bike_data["start_time"], infer_datetime_format=True)
    data["start_time"] = pd.to_datetime(bike_data["start_time"], format="%Y/%m/%d %H:%M:%S")


    data["start_month"] = bike_data["start_time"].dt.month
    data["start_day"] = bike_data["start_time"].dt.day
    data["start_hour"] = bike_data["start_time"].dt.hour
    data["start_week"] = bike_data["start_time"].dt.isocalendar().week
    data["weekday"] = bike_data["start_time"].dt.weekday + 1
    data["rounded_time"] = bike_data["start_time"].dt.round('30min')

I get the error:'DatetimeProperties' object has no attribute 'isocalendar'

I tried using the isocalendar method on a single date and it seems to work. I'm also sure that I have imported everything necessary.

0

1 Answer

Probably, your pandas version is too old. pandas.Series.dt.isocalendar (which is what you're trying to use) was added in version 1.1.0 (PR #33220).

You'll need to either update your pandas version to 1.1.0 or later, or use .dt.week, e.g.

data["start_week"] = bike_data["start_time"].dt.week
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest