pythonpython-3.xpandasdataframenan

Why am I getting only NaN values in all columns in Jupyter Notebook?


This is how the datset_1 looks like, enter image description here But when I am making pivot table out of it as show below I am only getting NaN as the volues in all the columns.

monthly_sales_data = pd.pivot_table(dataset_1, values = "Weekly_Sales", columns = "Year", index = "Month")
monthly_sales_data = monthly_sales_data.reindex(index = ['Jan','Feb','Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])
monthly_sales_data

I am only getting NaN values for the whole DataFrame:

NaN Values of the DataFrame


Solution

  • Change this:

    monthly_sales_data = monthly_sales_data.reindex(index = ['Jan','Feb','Mar',
    'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])
    

    to this:

    monthly_sales_data = monthly_sales_data.reindex(index = [1,2,3,4,5,6,7,8,9,10,11,12])