Below is the explanation of the above code set of test
Code explanation:
We start off by taking only the required columns with this command:
df = df[[‘Date’, ‘State/UnionTerritory’,’Cured’,’Deaths’,’Confirmed’]]
Then, we go ahead and rename the columns:
df.columns = [‘date’, ‘state’,’cured’,’deaths’,’confirmed’]
After that, we extract only those records, where the date is equal to 17th July:
today = df[df.date == ‘2020-07-17’]
Then, we go ahead and select the top 5 states with maximum no. of covide cases:
max_confirmed_cases=today.sort_values(by=”confirmed”,ascending=False)
max_confirmed_cases
top_states_confirmed=max_confirmed_cases[0:5]
Finally, we go ahead and make a bar-plot with this:
sns.set(rc={‘figure.figsize’:(15,10)})
sns.barplot(x=”state”,y=”confirmed”,data=top_states_confirmed,hue=”state”)
plt.show()
Here, we are using seaborn library to make the bar-plot. “State” column is mapped onto the x-axis and “confirmed” column is mapped onto the y-axis. The color of the bars is being determined by the “state” column.