WEEK 12 ( Stacked Area Plot )

In WEEK 12 , in the video of Stacked Area Plot , Sir made a function for plotting stacked area plot for status of different states related to Covid Pandemic. The Function was :

def plot_stacked_area_by_state(state):

df_ = df[state , ‘date’ , ‘status’]

df_[state] = pd.to_numeric(df_[state])

df_[‘date’] = pd.to_datetime(df_[‘date’])

df_ = df_.pivot_table(values=state,columns=‘status’,index=‘date’)

fig = plt.gcf();

fig.set_size_inches(15,6);

plt.stackplot(df_.index , df_.Confirmed/df_.sum(axis=1)

,df_.Recovered/df_.sum(axis=1)

,df_.Deceased/df_.sum(axis=1)

,labels = [‘Confirmed’,‘Recovered’,‘Deceased’]

,colors = [‘Orange’ , ‘Green’ , ‘Red’]);

plt.legend();

When I run this function , I get a error :

Can anyone help me out with the issue , what could be the reason of this error ?

Thank You

Hi Ayush,
Can you please expand the 3 hidden frames?

As the Screenshot is too large , I’m sharing my Google Collab Notebook link here :

Clean the data, there are negative values in the Confirmed column for Maharashtra which is causing error for area plot and stacked area plot. This issue wasn’t present when sir was working with the data.