0% found this document useful (0 votes)
13 views32 pages

Fds Practical Slips Solutions

Uploaded by

Pramod Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views32 pages

Fds Practical Slips Solutions

Uploaded by

Pramod Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

fds-practical-slips-solutions

November 8, 2023

[ ]: ***********************SLIP=01****************************************************************

[1]: *****Q1*****

import pandas as pd
import matplotlib.pyplot as plt
iris = pd.read_csv("C:\\Users\\dell\\iris.csv")
ax=plt.subplots(1,1,figsize=(10,8))
iris['Species'].value_counts().plot.pie(explode=[0.1,0.1,0.1],autopct='%1.
↪1f%%',shadow=True,figsize=(10,8))

plt.title("Iris Species %")


plt.show()

1
[2]: ******Q2******
import pandas as pd
df=pd.read_csv("data.csv")
df

fixed acidity volatile acidity citric acid residual sugar \


count 1599.000000 1599.000000 1599.000000 1599.000000
mean 8.319637 0.527821 0.270976 2.538806
std 1.741096 0.179060 0.194801 1.409928
min 4.600000 0.120000 0.000000 0.900000
25% 7.100000 0.390000 0.090000 1.900000
50% 7.900000 0.520000 0.260000 2.200000
75% 9.200000 0.640000 0.420000 2.600000
max 15.900000 1.580000 1.000000 15.500000

chlorides free sulfur dioxide total sulfur dioxide density \

2
count 1599.000000 1599.000000 1599.000000 1599.000000
mean 0.087467 15.874922 46.467792 0.996747
std 0.047065 10.460157 32.895324 0.001887
min 0.012000 1.000000 6.000000 0.990070
25% 0.070000 7.000000 22.000000 0.995600
50% 0.079000 14.000000 38.000000 0.996750
75% 0.090000 21.000000 62.000000 0.997835
max 0.611000 72.000000 289.000000 1.003690

pH sulphates alcohol quality


count 1599.000000 1599.000000 1599.000000 1599.000000
mean 3.311113 0.658149 10.422983 5.636023
std 0.154386 0.169507 1.065668 0.807569
min 2.740000 0.330000 8.400000 3.000000
25% 3.210000 0.550000 9.500000 5.000000
50% 3.310000 0.620000 10.200000 6.000000
75% 3.400000 0.730000 11.100000 6.000000
max 4.010000 2.000000 14.900000 8.000000

[ ]: ***********************SLIP=02****************************************************************

[9]: ******Q1*******

import pandas as pd
import numpy as np
df=pd.read_csv("C:\\Users\\dell\\data.csv")
df['Salary']=df['Salary'].fillna(df['Salary'].mean())
df['Age']=df['Age'].fillna(df['Age'].mean())
df

[9]: Country Age Salary Purchased


0 France 44.000000 72000.000000 No
1 Spain 27.000000 48000.000000 Yes
2 Germany 30.000000 54000.000000 No
3 Spain 38.000000 61000.000000 HOI
4 Germany 40.000000 63777.777778 Yes
5 France 35.000000 58000.000000 Yes
6 Spain 38.777778 52000.000000 No
7 France 48.000000 79000.000000 Yes
8 Germany 50.000000 83000.000000 No
9 France 37.000000 67000.000000 Yes

[10]: *****Q2.******

import numpy as np
import matplotlib.pyplot as plt

3
import seaborn as sns
df=pd.DataFrame(columns=['name','salary'])
df.loc[0]=['swati',980000]
df.loc[1]=['vaisu',970000]
df.loc[2]=['swara',96000]
df.loc[3]=['saru',950000]
df.loc[4]=['ram',99000]
df.plot.line(x="name",y="salary")
plt.show()

[13]: *****Q3.*******

import pandas as pd
df=pd.read_csv("C:\\Users\\dell\\HeightWeight.csv")
print("first ten rows of dataset",df.head(10))
print("last ten rows of dataset",df.tail(10))
print("random 20 rows of dataset",df.sample(20))
df

first ten rows of dataset Index Height(Inches) Weight(Pounds)

4
0 1 65.78331 112.9925
1 2 71.51521 136.4873
2 3 69.39874 153.0269
3 4 68.21660 142.3354
4 5 67.78781 144.2971
5 6 68.69784 123.3024
6 7 69.80204 141.4947
7 8 70.01472 136.4623
8 9 67.90265 112.3723
9 10 66.78236 120.6672
last ten rows of dataset Index Height(Inches) Weight(Pounds)
24990 24991 69.97767 125.3672
24991 24992 71.91656 128.2840
24992 24993 70.96218 146.1936
24993 24994 66.19462 118.7974
24994 24995 67.21126 127.6603
24995 24996 69.50215 118.0312
24996 24997 64.54826 120.1932
24997 24998 64.69855 118.2655
24998 24999 67.52918 132.2682
24999 25000 68.87761 124.8742
random 20 rows of dataset Index Height(Inches) Weight(Pounds)
5882 5883 66.73085 115.7089
7008 7009 66.74060 119.5494
9320 9321 66.77116 129.5425
1553 1554 65.31159 124.6278
7573 7574 67.73850 123.8408
19345 19346 68.86516 146.8200
11220 11221 69.00483 137.6559
6031 6032 70.70944 142.7307
6897 6898 68.05243 140.9604
9234 9235 68.41582 127.8615
7220 7221 70.86937 145.8197
22843 22844 69.51603 139.5932
19228 19229 68.03653 117.8885
1971 1972 70.92752 111.6473
1107 1108 69.50518 140.0956
1790 1791 68.00018 124.0930
22847 22848 65.55731 110.9407
18079 18080 65.87971 107.3144
2951 2952 67.23078 127.7070
18421 18422 68.13314 116.9677

[13]: Index Height(Inches) Weight(Pounds)


0 1 65.78331 112.9925
1 2 71.51521 136.4873
2 3 69.39874 153.0269

5
3 4 68.21660 142.3354
4 5 67.78781 144.2971
… … … …
24995 24996 69.50215 118.0312
24996 24997 64.54826 120.1932
24997 24998 64.69855 118.2655
24998 24999 67.52918 132.2682
24999 25000 68.87761 124.8742

[25000 rows x 3 columns]

[14]: df.shape

[14]: (25000, 3)

[ ]: ***********************SLIP=03****************************************************************

[15]: *****Q1.******

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
df=pd.read_csv("C:\\Users\\dell\\iris.csv")
df.head(3)
data=df[['SepalLengthCm','SepalWidthCm','PetalLengthCm','PetalLengthCm']]
print(data.head())
plt.figure(figsize=(10,7))
data.boxplot()

SepalLengthCm SepalWidthCm PetalLengthCm PetalLengthCm


0 5.1 3.5 1.4 1.4
1 4.9 3.0 1.4 1.4
2 4.7 3.2 1.3 1.3
3 4.6 3.1 1.5 1.5
4 5.0 3.6 1.4 1.4

[15]: <Axes: >

6
[16]: ******Q2.********

import pandas as pd
df=pd.read_csv('C:\\Users\\dell\\HeightWeight.csv')
print(df.describe())

Index Height(Inches) Weight(Pounds)


count 25000.000000 25000.000000 25000.000000
mean 12500.500000 67.993114 127.079421
std 7217.022701 1.901679 11.660898
min 1.000000 60.278360 78.014760
25% 6250.750000 66.704397 119.308675
50% 12500.500000 67.995700 127.157750
75% 18750.250000 69.272958 134.892850
max 25000.000000 75.152800 170.924000

[ ]: ***********************SLIP=04****************************************************************

[19]: ******Q1..*****
**HISTOGRAM**
import numpy as np
import matplotlib.pyplot as plt

7
data=np.random.randn(50)
plt.hist(data,color='red')

[19]: (array([ 1., 2., 4., 4., 12., 9., 8., 4., 4., 2.]),
array([-3.07883457, -2.55669464, -2.0345547 , -1.51241477, -0.99027484,
-0.4681349 , 0.05400503, 0.57614496, 1.0982849 , 1.62042483,
2.14256476]),
<BarContainer object of 10 artists>)

[22]: **BOXPLOT**
import numpy as np
import matplotlib.pyplot as plt
data=np.random.randn(50)
plt.boxplot(data,vert=False,)
plt.show()

8
[23]: **LINEPLOT**
import numpy as np
import matplotlib.pyplot as plt
data=np.random.randn(50)
data1=np.random.randn(50)
plt.plot(data,data1,color='yellow')

[23]: [<matplotlib.lines.Line2D at 0x26bbbf8ed10>]

9
[24]: **SCATTERPLOT**
import numpy as np
import matplotlib.pyplot as plt
data=np.random.randn(50)
data1=np.random.randn(50)
plt.scatter(data,data1,color='blue')

[24]: <matplotlib.collections.PathCollection at 0x26bbc13f0d0>

10
[32]: import pandas as pd
df=pd.read_csv("data.csv")
df

[32]: Country Age Salary Purchased


0 France 44.0 72000.0 No
1 Spain 27.0 48000.0 Yes
2 Germany 30.0 54000.0 No
3 Spain 38.0 61000.0 HOI
4 Germany 40.0 NaN Yes
5 France 35.0 58000.0 Yes
6 Spain NaN 52000.0 No
7 France 48.0 79000.0 Yes
8 Germany 50.0 83000.0 No
9 France 37.0 67000.0 Yes

[33]: df.shape

[33]: (10, 4)

[34]: df.columns

11
[34]: Index(['Country', 'Age', 'Salary', 'Purchased'], dtype='object')

[35]: df.dtypes

[35]: Country object


Age float64
Salary float64
Purchased object
dtype: object

[36]: df.info

[36]: <bound method DataFrame.info of Country Age Salary Purchased


0 France 44.0 72000.0 No
1 Spain 27.0 48000.0 Yes
2 Germany 30.0 54000.0 No
3 Spain 38.0 61000.0 HOI
4 Germany 40.0 NaN Yes
5 France 35.0 58000.0 Yes
6 Spain NaN 52000.0 No
7 France 48.0 79000.0 Yes
8 Germany 50.0 83000.0 No
9 France 37.0 67000.0 Yes>

[37]: df.describe()

[37]: Age Salary


count 9.000000 9.000000
mean 38.777778 63777.777778
std 7.693793 12265.579662
min 27.000000 48000.000000
25% 35.000000 54000.000000
50% 38.000000 61000.000000
75% 44.000000 72000.000000
max 50.000000 83000.000000

[ ]: *****SLIP NO=5 SAME AS SLIP NO=4******

[ ]: *****SLIP N0=6 SAME AS SLIP NO=2******

[ ]: ***********************SLIP=07****************************************************************

[38]: ***Q1...***

import numpy as np
import pandas as pd
from sklearn.preprocessing import OneHotEncoder

12
df=pd.read_csv("data.csv")
df.head()

[38]: Country Age Salary Purchased


0 France 44.0 72000.0 No
1 Spain 27.0 48000.0 Yes
2 Germany 30.0 54000.0 No
3 Spain 38.0 61000.0 HOI
4 Germany 40.0 NaN Yes

[39]: import numpy as np


import pandas as pd
from sklearn.preprocessing import LabelEncoder
df=pd.read_csv("data.csv")
df.head()

[39]: Country Age Salary Purchased


0 France 44.0 72000.0 No
1 Spain 27.0 48000.0 Yes
2 Germany 30.0 54000.0 No
3 Spain 38.0 61000.0 HOI
4 Germany 40.0 NaN Yes

[ ]: ***********************SLIP=08****************************************************************

[ ]: *****Q1..*****

[ ]:

[ ]:

[ ]: ***********************SLIP=09****************************************************************

[2]: *****Q1..****
***LINEPLOT***
import numpy as np
import matplotlib.pyplot as plt
data=np.random.randn(50)
data1=np.random.randn(50)
plt.plot(data,data1,color='yellow')

[2]: [<matplotlib.lines.Line2D at 0x241079efa90>]

13
[3]: ****SCATTER PLOT***
import numpy as np
import matplotlib.pyplot as plt
data=np.random.randn(50)
data1=np.random.randn(50)
plt.scatter(data,data1,color='blue')

[3]: <matplotlib.collections.PathCollection at 0x2410746a250>

14
[4]: *****Q2..****

import numpy as np
import matplotlib.pyplot as plt
subject=['comp','java','bt','wt','os','tcs','python']
marks=[98,100,65,89,56,67,100]
plt.pie(marks,labels=subject)

[4]: ([<matplotlib.patches.Wedge at 0x24107d9a950>,


<matplotlib.patches.Wedge at 0x2410868b150>,
<matplotlib.patches.Wedge at 0x2410869c490>,
<matplotlib.patches.Wedge at 0x2410869d950>,
<matplotlib.patches.Wedge at 0x24108639c10>,
<matplotlib.patches.Wedge at 0x2410869fd10>,
<matplotlib.patches.Wedge at 0x24107dc53d0>],
[Text(0.946050502272637, 0.5612383158246518, 'comp'),
Text(-0.051066714822199565, 1.0988139927382015, 'java'),
Text(-0.8934380219725504, 0.6416919049620127, 'bt'),
Text(-1.0738351826371801, -0.23849109109267413, 'wt'),
Text(-0.5843262254029676, -0.9319672002309526, 'os'),
Text(0.12294771038867845, -1.093107433196839, 'tcs'),
Text(0.9398613926963062, -0.571542266607606, 'python')])

15
[5]: ******Q3..****

import pandas as pd
df=pd.read_csv("Winequality-red.csv")
df

[5]: fixed acidity volatile acidity citric acid residual sugar chlorides \
0 7.4 0.700 0.00 1.9 0.076
1 7.8 0.880 0.00 2.6 0.098
2 7.8 0.760 0.04 2.3 0.092
3 11.2 0.280 0.56 1.9 0.075
4 7.4 0.700 0.00 1.9 0.076
… … … … … …
1594 6.2 0.600 0.08 2.0 0.090
1595 5.9 0.550 0.10 2.2 0.062
1596 6.3 0.510 0.13 2.3 0.076
1597 5.9 0.645 0.12 2.0 0.075
1598 6.0 0.310 0.47 3.6 0.067

free sulfur dioxide total sulfur dioxide density pH sulphates \


0 11.0 34.0 0.99780 3.51 0.56
1 25.0 67.0 0.99680 3.20 0.68
2 15.0 54.0 0.99700 3.26 0.65

16
3 17.0 60.0 0.99800 3.16 0.58
4 11.0 34.0 0.99780 3.51 0.56
… … … … … …
1594 32.0 44.0 0.99490 3.45 0.58
1595 39.0 51.0 0.99512 3.52 0.76
1596 29.0 40.0 0.99574 3.42 0.75
1597 32.0 44.0 0.99547 3.57 0.71
1598 18.0 42.0 0.99549 3.39 0.66

alcohol quality
0 9.4 5
1 9.8 5
2 9.8 5
3 9.8 6
4 9.4 5
… … …
1594 10.5 5
1595 11.2 6
1596 11.0 6
1597 10.2 5
1598 11.0 6

[1599 rows x 12 columns]

[7]: df.describe

[7]: <bound method NDFrame.describe of fixed acidity volatile acidity citric


acid residual sugar chlorides \
0 7.4 0.700 0.00 1.9 0.076
1 7.8 0.880 0.00 2.6 0.098
2 7.8 0.760 0.04 2.3 0.092
3 11.2 0.280 0.56 1.9 0.075
4 7.4 0.700 0.00 1.9 0.076
… … … … … …
1594 6.2 0.600 0.08 2.0 0.090
1595 5.9 0.550 0.10 2.2 0.062
1596 6.3 0.510 0.13 2.3 0.076
1597 5.9 0.645 0.12 2.0 0.075
1598 6.0 0.310 0.47 3.6 0.067

free sulfur dioxide total sulfur dioxide density pH sulphates \


0 11.0 34.0 0.99780 3.51 0.56
1 25.0 67.0 0.99680 3.20 0.68
2 15.0 54.0 0.99700 3.26 0.65
3 17.0 60.0 0.99800 3.16 0.58
4 11.0 34.0 0.99780 3.51 0.56
… … … … … …

17
1594 32.0 44.0 0.99490 3.45 0.58
1595 39.0 51.0 0.99512 3.52 0.76
1596 29.0 40.0 0.99574 3.42 0.75
1597 32.0 44.0 0.99547 3.57 0.71
1598 18.0 42.0 0.99549 3.39 0.66

alcohol quality
0 9.4 5
1 9.8 5
2 9.8 5
3 9.8 6
4 9.4 5
… … …
1594 10.5 5
1595 11.2 6
1596 11.0 6
1597 10.2 5
1598 11.0 6

[1599 rows x 12 columns]>

[8]: df.shape

[8]: (1599, 12)

[9]: df.head(3)

[9]: fixed acidity volatile acidity citric acid residual sugar chlorides \
0 7.4 0.70 0.00 1.9 0.076
1 7.8 0.88 0.00 2.6 0.098
2 7.8 0.76 0.04 2.3 0.092

free sulfur dioxide total sulfur dioxide density pH sulphates \


0 11.0 34.0 0.9978 3.51 0.56
1 25.0 67.0 0.9968 3.20 0.68
2 15.0 54.0 0.9970 3.26 0.65

alcohol quality
0 9.4 5
1 9.8 5
2 9.8 5

[ ]: ***********************SLIP=10****************************************************************

[ ]: Q1

[ ]: Q2

18
[ ]:

[ ]: ***********************SLIP=11*********SAME AS␣
↪SLIP=01*************************************************************************

[21]: ****Q1...***

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
df=pd.read_csv("C:\\Users\\dell\\iris.csv")
data=[10,20,30]
data1=['SepalLengthCm','SepalWidthCm','PetalLengthCm']
plt.pie(data,labels=data1)

[21]: ([<matplotlib.patches.Wedge at 0x24114055d50>,


<matplotlib.patches.Wedge at 0x24114062310>,
<matplotlib.patches.Wedge at 0x24114063650>],
[Text(0.9526279355804298, 0.5500000148652441, 'SepalLengthCm'),
Text(-0.5500000594609755, 0.9526279098330699, 'SepalWidthCm'),
Text(1.0298943251329445e-07, -1.0999999999999954, 'PetalLengthCm')])

19
[22]: ***Q2***
import pandas as pd
df=pd.read_csv('C:\\Users\\dell\\winequality-red.csv')
print(df.describe())

fixed acidity volatile acidity citric acid residual sugar \


count 1599.000000 1599.000000 1599.000000 1599.000000
mean 8.319637 0.527821 0.270976 2.538806
std 1.741096 0.179060 0.194801 1.409928
min 4.600000 0.120000 0.000000 0.900000
25% 7.100000 0.390000 0.090000 1.900000
50% 7.900000 0.520000 0.260000 2.200000
75% 9.200000 0.640000 0.420000 2.600000
max 15.900000 1.580000 1.000000 15.500000

chlorides free sulfur dioxide total sulfur dioxide density \


count 1599.000000 1599.000000 1599.000000 1599.000000
mean 0.087467 15.874922 46.467792 0.996747
std 0.047065 10.460157 32.895324 0.001887
min 0.012000 1.000000 6.000000 0.990070
25% 0.070000 7.000000 22.000000 0.995600
50% 0.079000 14.000000 38.000000 0.996750
75% 0.090000 21.000000 62.000000 0.997835
max 0.611000 72.000000 289.000000 1.003690

pH sulphates alcohol quality


count 1599.000000 1599.000000 1599.000000 1599.000000
mean 3.311113 0.658149 10.422983 5.636023
std 0.154386 0.169507 1.065668 0.807569
min 2.740000 0.330000 8.400000 3.000000
25% 3.210000 0.550000 9.500000 5.000000
50% 3.310000 0.620000 10.200000 6.000000
75% 3.400000 0.730000 11.100000 6.000000
max 4.010000 2.000000 14.900000 8.000000

[ ]: ***********************SLIP=12****************************************************************

[ ]: ****Q1****SAME AS SLIP=09=Q1

[24]: import pandas as pd


df=pd.DataFrame(columns=['name','salary','department'])
df.loc[0]=['swati',24000,'comp']
df.loc[1]=['ruhi',23000,'elec']
df.loc[2]=['ram',70000,'os']
df.loc[3]=['sham',50000,'python']
df.loc[4]=['saru',67000,'maths']
df.loc[5]=['ram',77000,'comp']

20
df.loc[6]=['sai',5555,'bt']
df.loc[7]=['www',45000,'wt']
df.loc[8]=['sham',67000,'java']
df.loc[9]=['sakshu',66666,'python']
df

[24]: name salary department


0 swati 24000 comp
1 ruhi 23000 elec
2 ram 70000 os
3 sham 50000 python
4 saru 67000 maths
5 ram 77000 comp
6 sai 5555 bt
7 www 45000 wt
8 sham 67000 java
9 sakshu 66666 python

[25]: df.isnull()

[25]: name salary department


0 False False False
1 False False False
2 False False False
3 False False False
4 False False False
5 False False False
6 False False False
7 False False False
8 False False False
9 False False False

[26]: df.dropna()

[26]: name salary department


0 swati 24000 comp
1 ruhi 23000 elec
2 ram 70000 os
3 sham 50000 python
4 saru 67000 maths
5 ram 77000 comp
6 sai 5555 bt
7 www 45000 wt
8 sham 67000 java
9 sakshu 66666 python

[28]: df.empty

21
[28]: False

[ ]: ***********************SLIP=13****************************************************************

[ ]: ****Q1***

[29]: ***Q2..***
import numpy as np
data=np.array([[0,1],[2,3]])
print("original flattened array")
print(data)
print("minimum flattened array")
print(np.min(data))
print("maximum flattened array")
print(np.max(data))

original flattened array


[[0 1]
[2 3]]
minimum flattened array
0
maximum flattened array
3

[ ]: ***********************SLIP=14****************************************************************

[ ]: ***Q1****

[30]: *****Q2****

import pandas as pd
df=pd.read_csv("advertising.csv")
df

[30]: TV Radio Newspaper Sales


0 230.1 37.8 69.2 22.1
1 44.5 39.3 45.1 10.4
2 17.2 45.9 69.3 12.0
3 151.5 41.3 58.5 16.5
4 180.8 10.8 58.4 17.9
.. … … … …
195 38.2 3.7 13.8 7.6
196 94.2 4.9 8.1 14.0
197 177.0 9.3 6.4 14.8
198 283.6 42.0 66.2 25.5
199 232.1 8.6 8.7 18.4

22
[200 rows x 4 columns]

[ ]: ***********************SLIP=15****************************************************************

[ ]: ****Q1..**** SAME AS SLIP=12

[ ]: ****Q2...**** SAME AS SLIP=09

[ ]: ***********************SLIP=16****************************************************************

[1]: ****Q1...****

import numpy as np
import matplotlib.pyplot as plt
subject=['comp','java','bt','wt','os','tcs','python']
marks=[98,100,65,89,56,67,100]
plt.pie(marks,labels=subject)

[1]: ([<matplotlib.patches.Wedge at 0x2939e5626d0>,


<matplotlib.patches.Wedge at 0x2939e563e50>,
<matplotlib.patches.Wedge at 0x2939e5711d0>,
<matplotlib.patches.Wedge at 0x2939e5726d0>,
<matplotlib.patches.Wedge at 0x2939e573a90>,
<matplotlib.patches.Wedge at 0x2939e578f90>,
<matplotlib.patches.Wedge at 0x2939e57a550>],
[Text(0.946050502272637, 0.5612383158246518, 'comp'),
Text(-0.051066714822199565, 1.0988139927382015, 'java'),
Text(-0.8934380219725504, 0.6416919049620127, 'bt'),
Text(-1.0738351826371801, -0.23849109109267413, 'wt'),
Text(-0.5843262254029676, -0.9319672002309526, 'os'),
Text(0.12294771038867845, -1.093107433196839, 'tcs'),
Text(0.9398613926963062, -0.571542266607606, 'python')])

23
[2]: import numpy as np
import matplotlib.pyplot as plt
subject=['comp','java','bt','wt','os','tcs','python']
marks=[98,100,65,89,56,67,100]
plt.bar(subject,marks)
plt.show()

24
[ ]: ****Q2...****

[ ]: ***********************SLIP=17****************************************************************

[3]: ****Q1****

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df=pd.read_csv("C:\\Users\\dell\\iris.csv")
df.plot.scatter(x='SepalLengthCm',y='PetalLengthCm')
print(df)

Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm \


0 1 5.1 3.5 1.4 0.2
1 2 4.9 3.0 1.4 0.2
2 3 4.7 3.2 1.3 0.2
3 4 4.6 3.1 1.5 0.2
4 5 5.0 3.6 1.4 0.2
.. … … … … …
145 146 6.7 3.0 5.2 2.3
146 147 6.3 2.5 5.0 1.9

25
147 148 6.5 3.0 5.2 2.0
148 149 6.2 3.4 5.4 2.3
149 150 5.9 3.0 5.1 1.8

Species
0 Iris-setosa
1 Iris-setosa
2 Iris-setosa
3 Iris-setosa
4 Iris-setosa
.. …
145 Iris-virginica
146 Iris-virginica
147 Iris-virginica
148 Iris-virginica
149 Iris-virginica

[150 rows x 6 columns]

[4]: ****Q2****

26
import pandas as pd
df=pd.DataFrame(columns=['name','age','salary'])
df.loc[0]=['swati',23,24000]
df.loc[1]=['ram',45,23000]
df.loc[2]=['sham',34,70000]
df.loc[3]=['saru',12,50000]
df.loc[4]=['ruhi',45,67000]
df.loc[5]=['rani',23,77000]
df.loc[6]=['venky',24,5555]
df.loc[7]=['lata',56,45000]
df.loc[8]=['sai',10,67000]
df.loc[9]=['aishu',18,66666]
df

[4]: name age salary


0 swati 23 24000
1 ram 45 23000
2 sham 34 70000
3 saru 12 50000
4 ruhi 45 67000
5 rani 23 77000
6 venky 24 5555
7 lata 56 45000
8 sai 10 67000
9 aishu 18 66666

[ ]: ***********************SLIP=18****************************************************************

[ ]: ***Q1*** SAME AS SLIP=03

[5]: *****Q2****

import pandas as pd
df=pd.read_csv("C:\\Users\\dell\\HeightWeight.csv")
print("first five rows of dataset",df.head(5))
print("last five rows of dataset",df.tail(5))
print("random ten rows of dataset",df.sample(10))
df

first five rows of dataset Index Height(Inches) Weight(Pounds)


0 1 65.78331 112.9925
1 2 71.51521 136.4873
2 3 69.39874 153.0269
3 4 68.21660 142.3354
4 5 67.78781 144.2971
last five rows of dataset Index Height(Inches) Weight(Pounds)
24995 24996 69.50215 118.0312

27
24996 24997 64.54826 120.1932
24997 24998 64.69855 118.2655
24998 24999 67.52918 132.2682
24999 25000 68.87761 124.8742
random ten rows of dataset Index Height(Inches) Weight(Pounds)
3452 3453 68.47258 122.6694
3641 3642 66.66861 123.3439
8797 8798 66.36935 129.6092
12844 12845 65.19866 114.6411
15571 15572 67.21663 117.1835
24152 24153 67.57214 126.6289
24297 24298 67.14450 128.2922
4121 4122 67.79469 135.8259
5008 5009 70.88882 160.0364
19735 19736 65.48782 127.7492

[5]: Index Height(Inches) Weight(Pounds)


0 1 65.78331 112.9925
1 2 71.51521 136.4873
2 3 69.39874 153.0269
3 4 68.21660 142.3354
4 5 67.78781 144.2971
… … … …
24995 24996 69.50215 118.0312
24996 24997 64.54826 120.1932
24997 24998 64.69855 118.2655
24998 24999 67.52918 132.2682
24999 25000 68.87761 124.8742

[25000 rows x 3 columns]

[ ]: ***********************SLIP=19****************************************************************

[ ]: ****Q1*** SAME AS SLIP=17

[ ]: ****Q2*** SAME AS SLIP=

[6]: ****Q3..***

import pandas as pd
df=pd.DataFrame(columns=['name','age','percentage'])
df.loc[0]=['swati',23,89]
df.loc[1]=['ram',45,67]
df.loc[2]=['sham',34,70]
df.loc[3]=['saru',12,50]
df.loc[4]=['ruhi',45,67]
df['remark']=None

28
df

[6]: name age percentage remark


0 swati 23 89 None
1 ram 45 67 None
2 sham 34 70 None
3 saru 12 50 None
4 ruhi 45 67 None

[ ]: ***********************SLIP=20****************************************************************

[4]: ***Q1***SAME AS ANOTHER SLIPS

***Q2***

import numpy as np
import pandas as np
import matplotlib.pyplot as plt
x=[10,20,30,49,57]
y=[12,14,16,18,20]
plt.boxplot(x,y,vert=False)
plt.show()

29
[ ]: ***********************SLIP=21************************************************************

[8]: ****Q1***

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df=pd.read_csv("C:\\Users\\dell\\iris.csv")
data=['SepalLengthCm','PetalLengthCm','SepaWidthCm']
data1=[1,2,3,]
plt.bar(data,data1)
plt.show()

[13]: ****Q2***

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df=pd.read_csv("C:\\Users\\dell\\iris.csv")
data=['SepalLengthCm','PetalLengthCm','SepaWidthCm']
plt.hist(data)
plt.show()

30
[ ]: ***********************SLIP=22**************************************************

[ ]:

[ ]:

[ ]:

[ ]:

[ ]: ***********************SLIP=23**************************************************

[ ]:

[ ]:

[ ]:

[ ]:

[ ]: ***********************SLIP=24************************************************************

31
SAME AS SLIP=21

[ ]: ***********************SLIP=25************************************************************
SAME AS SLIP=15

[ ]: ***********************SLIP=26************************************************************
SAME AS SLIP=15

[ ]: ***********************SLIP=27************************************************************
SAME AS SLIP=7

[ ]: ***********************SLIP=28************************************************************
SAME AS SLIP=19

[ ]: ***********************SLIP=29************************************************************
SAME AS SLIP=7

[ ]: ***********************SLIP=30************************************************************
SAME AS SLIP=15

32

You might also like