Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

In [1]:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

In [3]:

globalWar=pd.read_csv(r"C:\Users\user\Desktop\Datasets\globalWarming.csv")
df=globalWar.drop(columns=["Country Code","Indicator Name","Indicator Code"],axis=1).set

In [4]:

df

Out[4]:

2000 2001 2002 2003 2004 2005 2006 200

Country
Name

United
20.178751 19.636505 19.613404 19.564105 19.658371 19.591885 19.094067 19.2
States

United
9.199549 9.233175 8.904123 9.053278 8.989140 8.982939 8.898710 8.6
Kingdom

India 0.979870 0.971698 0.967381 0.992392 1.025028 1.068563 1.121982 1.1

China 2.696862 2.742121 3.007083 3.524074 4.037991 4.523178 4.980314 5.3

Russian
10.627121 10.669603 10.715901 11.090647 11.120627 11.253529 11.669122 11.6
Federation

Australia 17.200610 16.733367 17.370452 16.901959 17.026515 17.169711 17.651398 17.8

France 5.946665 6.153061 6.068664 6.115998 6.120079 6.099599 5.906266 5.7

Germany 10.095640 10.366287 10.058673 9.969355 9.898682 9.666372 9.911476 9.4

Canada 17.367115 16.985030 16.559378 17.461199 17.258911 17.251083 16.696694 16.8

Brazil 1.871118 1.898354 1.844380 1.762482 1.828672 1.858088 1.839394 1.9

Argentina 3.835574 3.568600 3.291548 3.525584 4.069058 4.141237 4.434821 4.3

Pakistan 0.768458 0.764702 0.788668 0.804959 0.872802 0.887768 0.929857 0.9

Nepal 0.129282 0.135226 0.106877 0.113902 0.105477 0.120277 0.098812 0.0

Bangladesh 0.211802 0.242020 0.246756 0.256602 0.266823 0.275247 0.299529 0.3

Japan 9.622352 9.464309 9.573130 9.725282 9.909203 9.698883 9.632049 9.7


In [25]:

plt.figure(figsize=(12,8))
ann={"orientation":"horizontal"}
sns.heatmap(df,cmap="coolwarm",annot=True,linewidth=1,cbar=True,
vmin=2,vmax=20,cbar_kws=ann)

Out[25]:

<AxesSubplot:ylabel='Country Name'>
In [26]:

flight=sns.load_dataset("flights")
flight

Out[26]:

year month passengers

0 1949 Jan 112

1 1949 Feb 118

2 1949 Mar 132

3 1949 Apr 129

4 1949 May 121

... ... ... ...

139 1960 Aug 606

140 1960 Sep 508

141 1960 Oct 461

142 1960 Nov 390

143 1960 Dec 432

144 rows × 3 columns


In [28]:

flight=sns.load_dataset("titanic")
flight

Out[28]:

sibsp parch fare embarked class who adult_male deck embark_town alive alone

1 0 7.2500 S Third man True NaN Southampton no False

1 0 71.2833 C First woman False C Cherbourg yes False

0 0 7.9250 S Third woman False NaN Southampton yes True

1 0 53.1000 S First woman False C Southampton yes False

0 0 8.0500 S Third man True NaN Southampton no True

... ... ... ... ... ... ... ... ... ... ...

0 0 13.0000 S Second man True NaN Southampton no True

0 0 30.0000 S First woman False B Southampton yes True

1 2 23.4500 S Third woman False NaN Southampton no False

0 0 30.0000 C First man True C Cherbourg yes True

0 0 7.7500 Q Third man True NaN Queenstown no True

In [34]:

# creating a dataframe
df = pd.DataFrame({'A': ['John', 'Boby', 'Mina', 'Peter', 'Nicky','Mina'],
'B': ['Masters', 'Graduate', 'Graduate', 'Masters', 'Graduate','Gradua
'C': [27, 23, 21, 23, 24,22]})

df

Out[34]:

A B C

0 John Masters 27

1 Boby Graduate 23

2 Mina Graduate 21

3 Peter Masters 23

4 Nicky Graduate 24

5 Mina Graduate 22
In [35]:

table = pd.pivot_table(df, index =['A', 'B'])


table

Out[35]:

A B

Boby Graduate 23.0

John Masters 27.0

Mina Graduate 21.5

Nicky Graduate 24.0

Peter Masters 23.0

In [36]:

table = pd.pivot_table(df, values ='A', index =['B', 'C'],


columns =['B'], aggfunc = np.sum)

table

Out[36]:

B Graduate Masters

B C

Graduate 21 Mina NaN

22 Mina NaN

23 Boby NaN

24 Nicky NaN

Masters 23 NaN Peter

27 NaN John
In [38]:

df=pd.read_excel(r"C:\Users\user\Desktop\collegeData.xlsx",sheet_name="Sheet2")
df

Out[38]:

Student CollegeName Course Marks

0 pooja DSD BCA 26

1 poonam DSD MCA 83

2 lalit DSD BBA 12

3 manav DSD BCA 3

4 sonia DSD MCA 80

5 gagan DSD BBA 71

6 harpal DSD BBA 15

7 pooja KIIT BCA 58

8 poonam KIIT MCA 44

9 lalit KIIT BBA 94

10 manav KIIT BCA 13

11 sonia KIIT MCA 80

12 gagan KIIT BBA 6

13 harpal KIIT BBA 93


In [44]:

table = pd.pivot_table(df, values ='Marks', index =['Student'],


columns =['CollegeName','Course'], aggfunc = np.sum)

table

Out[44]:

CollegeName DSD KIIT

Course BBA BCA MCA BBA BCA MCA

Student

gagan 71.0 NaN NaN 6.0 NaN NaN

harpal 15.0 NaN NaN 93.0 NaN NaN

lalit 12.0 NaN NaN 94.0 NaN NaN

manav NaN 3.0 NaN NaN 13.0 NaN

pooja NaN 26.0 NaN NaN 58.0 NaN

poonam NaN NaN 83.0 NaN NaN 44.0

sonia NaN NaN 80.0 NaN NaN 80.0

In [ ]:

You might also like