Skip to content

AttributeError: 'DataFrame' object has no attribute 'ix' in Time Series Forecastings #43

Open
@Lancashire3000

Description

@Lancashire3000

Hi,
I tried to run Time Series Forecastings example. From

first_date = store.ix[np.min(list(np.where(store['office_sales'] > store['furniture_sales'])[0])), 'Order Date']

print("Office supplies first time produced higher sales than furniture is {}.".format(first_date.date()))

I got
AttributeError: 'DataFrame' object has no attribute 'ix'
If I replace ix to iloc, based on https://stackoverflow.com/questions/59991397/attributeerror-dataframe-object-has-no-attribute-ix then I got
ValueError: Location based indexing can only have [integer, integer slice (START point is INCLUDED, END point is EXCLUDED), listlike of integers, boolean array] types

How to fix it? Thanks

Activity

aniketDash7

aniketDash7 commented on Oct 5, 2023

@aniketDash7

The .ix indexer has been deprecated in Pandas, which is why you're getting an AttributeError. Instead, you should use .loc or .iloc for label-based or integer-location based indexing, respectively.

In the context of your code, you're trying to find the first date where office sales were higher than furniture sales. Here's how you can fix it using .loc:

first_date = store.loc[store['office_sales'] > store['furniture_sales'], 'Order Date'].min()

print("Office supplies first time produced higher sales than furniture is {}.".format(first_date.date()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @aniketDash7@Lancashire3000

        Issue actions

          `AttributeError: 'DataFrame' object has no attribute 'ix'` in `Time Series Forecastings` · Issue #43 · susanli2016/Machine-Learning-with-Python