Python Pandas Project
Python Pandas Project
CORONAVIRUS
Class : 12th
Stream : Commerce
Last but not the least I would like to thank my classmates who
have helped me a lot…
Date:
INDEX
SR. DESCRIPTION PAGE NO.
NO.
1 Pandas 1
2 Data Frame 2
3 Add/Drop/Sorting 3
4 Mean/Mode/Median 4
5 Sum/Count/Variation 5
6 Quantile/Pivoting/Apply 6
7 Head&Tail/Min/Max 7
9 Pie/Boxplot/Histogram 10-12
Hardware: - Intel(R)Core (TM) i5-3470 CPU @ 3.20GHz, 8.00 GB RAM, x64 operating system.
Software: - Jupyter Notebook (Anaconda3), Microsoft Word 2019
Overview
Pandas is a Python package providing fast, flexible, and
expressive data structures designed to make working with
“relational” or “labeled” data both easy and intuitive. It aims to
be the fundamental high-level building block for doing
practical, real world data analysis in Python. Additionally, it has
the broader goal of becoming the most powerful and flexible
open-source data analysis / manipulation tool available in any
language. It is already well on its way toward this goal.
DATAFRAME
# In[1]:
import pandas as pd
import matplotlib.pyplot as pl
import numpy as np
# In[2]:
data=
{ 'TotalCases':[14774167, 9608418,
6534951,2431731,2268552,1699145,1690432,1688939,1454631,1352607,1156770,1
152283,1041846,1016835,970860,805804,801716,765997,587439,569707],
'TotalRecovered':
[8663603,9058822,5744369,1916396,1688352,1650250,1010010,870385,1281955,1
240990,852719,820600,666413,708106,903958,740450,412533,423142,38858,4704
49],
'TotalDeaths':
[285656,139736,175951,42384,54767,46252,60617,58852,39512,37446,108863,186
91,19359,49695,36195,21963,13421,14509,17142,17589],
'ActiveCases':
[5824908,409860,614614,472654,2045433,160250,601425,757702,133164,74150,1
95188,312992,356072,259034,30707,43391,375762,328346,531493,81669]}
# In[3]:
# In[4]:
a.index.name='Country'
# In[5]:
print(a)
# Sorting
# In[6]:
sor=a.sort_values(['ActiveCases'], ascending=False)
# In[7]:
print(sor)
# Drop Column
# In[8]:
dro=a.drop(['TotalCases'], axis=1)
# In[9]:
print(dro)
# Add Column
# In[10]:
b=[14774167, 9608418,
6534951,2431731,2268552,1699145,1690432,1688939,1454631,1352607,1156770,1
152283,1041846,1016835,970860,805804,801716,765997,587439,569707]
# In[11]:
dro['TotalCases']=b
# In[12]:
print(dro)
# Mean
# In[13]:
c=a.mean()
print(c)
# In[41]:
d=a['TotalCases'].mean()
print(d)
# Mode
# In[42]:
e=a.mode()
print(e)
# In[43]:
f=a['ActiveCases'].mode()
print(f)
# Median
# In[45]:
g=a.median()
print(g)
# In[46]:
h=a['TotalDeaths'].median()
print(h)
# Sum
# In[47]:
i=a.sum()
print(i)
# In[48]:
j=a['TotalRecovered'].sum()
print(j)
# Count
# In[49]:
k=a.count()
print(k)
# In[50]:
l=a['TotalCases'].count()
print(l)
# Variation
# In[51]:
m=a.var()
print(m)
# In[52]:
n=a['ActiveCases'].var()
print(n)
# Quantile
# In[53]:
o=a.quantile(q=[0.25,0.50,0.75,1.00])
print(o)
# Pivoting
# In[54]:
p=a.loc['USA'].pipe(np.add,100000).pipe(np.multiply,50)
print(p)
# In[55]:
q=a.iloc[0].pipe(np.add,100000).pipe(np.multiply,50)
print(q)
# In[57]:
r=a['SQRT']=a['TotalCases'].apply(np.sqrt)
print(r)
# In[29]:
print(a)
# In[58]:
s=a.applymap(np.sqrt)
print(s)
# MIN/MAX
# In[31]:
t=a.max()
print(t)
# In[59]:
u=a.min()
print(u)
# Head & Tail
# In[60]:
v=a.head(2)
print(v)
# In[61]:
w=a.tail(2)
print(w)
# Pyplot
# Graphs
# Line Graph
# In[35]:
CC=('USA', 'India','Brazil','Russia','France')
TR=(8663603,9058822,5744369,1916396,1688352)
TD=(285656,139736,175951,42384,54767)
AC=(5824908,409860,614614,472654,2045433)
# In[62]:
pl.figure(figsize=[12,8])
pl.grid()
pl.xlabel('Countries')
pl.ylabel('Population')
pl.title('CoronaVirus')
pl.legend(loc=1)
pl.show()
# Bar Graph
# In[63]:
pl.figure(figsize=(10,7))
pl.grid()
pl.legend(loc=1)
pl.title('CoronaVirus')
pl.xlabel('Countries')
pl.ylabel('Population')
pl.show()
# Pie
# In[64]:
pl.figure(figsize=[12,7])
pl.axis('equal')
exp=[0,0.05,0,0,0]
pl.show()
# BoxPlot
pl.figure(figsize=[12,7])
Ls=[TC,TR,TD,AC]
pl.title('CoronaVirus BoxPlot')
pl.xlabel('Countries')
pl.ylabel('Population')
pl.show()
# Histogram
import numpy as np
mu=100
sigma=15
x=mu+sigma*np.random.randn(10000)
pl.figure(figsize=[12,6])
pl.title('GivenExample')
pl.xlabel('X-Axis')
pl.ylabel('Y-Axis')
pl.show()
Bibliography
o Information Practice for Class XII by Sumit Arora
o https://www.python.org
o https://www.stackoverflow.com
o https://www.w3school.com
o https://codeproject.com
o https://codeacademy.com
o https://www.quru99.com
o https://tutorialpoint.com