converting the azure machine learning forecast into a dataframe

braxx 461 Reputation points
2023-01-27T11:55:46.81+00:00

I am building the forecasting model in jupiter notebook in python in Azure Machine Learning service. To do so I am using the forecast function documented here.

The problem is with the output. It looks like this:

User's image

Not sure even how do i call it. It does not look like a typical dataframe. More like a pivot table. Some of the columns starting from "automl_target_col_wasnull" are automaticaly added by the function.

How do I convert it into a dataframe?

I am interested in only the columns "Month", "Branch" and the last one containg the forecast called "_automl_target_col" . The docs do not show any of such example

Azure Machine Learning
{count} votes

1 answer

Sort by: Most helpful
  1. Ramr-msft 17,836 Reputation points
    2023-02-06T06:57:46.9533333+00:00

    @braxx Thanks for the question. To filter only the columns you are interested in, you can use the pandas dataframe method "df.filter()". This method takes a list of column names as input and returns a new dataframe with only the specified columns.

    For example, to filter only the columns "Month", "Branch", and "_automl_target_col" from the dataframe "df", you can use the following code:

    # filter only the columns you are interested in
    df = df.filter(['Month', 'Branch', '_automl_target_col'])
    

    Alternatively, you can also use the "df.loc[]" method to select specific columns by their names. This method takes a list of column names as input and returns a new dataframe with only the specified columns.

    For example, to filter only the columns "Month", "Branch", and "_automl_target_col" from the dataframe "df", you can use the following code:

    # filter only the columns you are interested in
    df = df.loc[:, ['Month', 'Branch', '_automl_target_col']]
    

    Both methods will return a new dataframe with only the specified columns, and the original dataframe will remain unchanged. You can then use this new dataframe for further analysis or modeling.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.