Day 17 : Visualization of data using matplotlib (corona virus analysis)
Hey Guys,
previously we learned about data manipulation and cleaning of data
Today we will learn about visualization of data using matplotlib
What is matplotlib?
Matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy.
Install matplotlib
pip install matplotlib
Let's have Fun with matplotlib
For dataset : https://www.kaggle.com/sudalairajkumar/novel-corona-virus-2019-dataset
Code:
#import libraries
%matplotlib inline
import matplotlib.pyplot as plt
import pandas as pd
#Read csv file which is get from kaggle dataset
df=pd.read_csv("corona/corona_data.csv")
print(df.head())
#This is used to filter data by country
new_df=df.loc[df['Country/Region'] == "India"]
print(new_df)
#Here we get information about dates and confirmed cases
dates=new_df["ObservationDate"]
confirmed=new_df["Confirmed"]
#Basically as name says plot data
#dates on x-axis
#confirmed on y-axis
#color your choice deafult is black
plt.plot(dates,confirmed,color="red")
#scale on x-axis
#1st parameter is list of tick
#2nd is steps
#3rd is rotate label
plt.xticks(range(0,new_df.shape[0],5),dates.loc[::5],rotation=90)
#x-axis lable
plt.xlabel('Date',fontsize=18)
#if you see all the data, you will find data is inconsistent
somewhere it is female or Female and other gender is 4000
And we are dealing with computer so female and Female are different
We have to make that data consistant.
so replace female with Female
df=df.replace("female", "Female")
#here we get unique values for each gender or sex
m=df["sex"].value_counts()
print(m)
#here we get unique values for each gender or sex
data=df["sex"].value_counts()
print(data)
Convert data into list for y-axis
count=list(data)
Gender for x-axis
gender=["Male","Female"]
plt.subplot(131)
#Plot bar chart
x-axis : gender
y-axis : gender count
plt.bar(gender, count)
Simple is that
You can have more fun...
Try for other countries and daily increase.
previously we learned about data manipulation and cleaning of data
Today we will learn about visualization of data using matplotlib
What is matplotlib?
Matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy.
Install matplotlib
pip install matplotlib
Let's have Fun with matplotlib
For dataset : https://www.kaggle.com/sudalairajkumar/novel-corona-virus-2019-dataset
Code:
#import libraries
%matplotlib inline
import matplotlib.pyplot as plt
import pandas as pd
#Read csv file which is get from kaggle dataset
df=pd.read_csv("corona/corona_data.csv")
print(df.head())
#This is used to filter data by country
new_df=df.loc[df['Country/Region'] == "India"]
print(new_df)
#Here we get information about dates and confirmed cases
dates=new_df["ObservationDate"]
confirmed=new_df["Confirmed"]
#Basically as name says plot data
#dates on x-axis
#confirmed on y-axis
#color your choice deafult is black
plt.plot(dates,confirmed,color="red")
#scale on x-axis
#1st parameter is list of tick
#2nd is steps
#3rd is rotate label
plt.xticks(range(0,new_df.shape[0],5),dates.loc[::5],rotation=90)
#x-axis lable
plt.xlabel('Date',fontsize=18)
#if you see all the data, you will find data is inconsistent
somewhere it is female or Female and other gender is 4000
And we are dealing with computer so female and Female are different
We have to make that data consistant.
so replace female with Female
df=df.replace("female", "Female")
#here we get unique values for each gender or sex
m=df["sex"].value_counts()
print(m)
Male 707 Female 556 4000 1 Name: sex, dtype: int64
There is 4000 gender we have to remove thisdf=df[df.sex!= "4000"]
#here we get unique values for each gender or sex
data=df["sex"].value_counts()
print(data)
Male 707 Female 556
Convert data into list for y-axis
count=list(data)
Gender for x-axis
gender=["Male","Female"]
plt.subplot(131)
#Plot bar chart
x-axis : gender
y-axis : gender count
plt.bar(gender, count)
Simple is that
You can have more fun...
Try for other countries and daily increase.
❤❤Quarantine python group link ❤❤
8805271377 WhatsApp
Follow here ❤
@mr._mephisto_ Instagram
There will be no restrictions just feel free to learn.
Share and take one more step to share knowledge to others.
Believe in yourself 🤟 you are awesome.
Be safe, Be happy😁
Take care of yourself and your family
Of course watch movies and series🤟😉
And follow the guidelines of government
Comments
Post a Comment