Informatics Practices

Consider the DataFrame wdf as shown below :

 minTempmaxTempRainfallEvaporation
02.98.024.30.0
13.114.026.93.6
26.213.723.43.6
35.313.315.539.8
46.317.616.12.8
55.418.216.90.0
65.521.118.20.2
74.818.317.00.0
83.620.819.50.0
97.719.422.816.2
109.924.125.20.0
1111.828.527.30.2
1213.229.127.90.0
1316.824.130.90.0
1419.428.131.20.0
1521.634.432.10.0
1620.433.831.20.0
1718.526.730.01.2
1818.832.432.30.6
1917.628.633.40.0
2019.730.333.40.0

(a) Write statement(s) to calculate minimum value for each of the columns.

(b) Write statement(s) to calculate maximum value for each of the rows.

(c) Write statement(s) to calculate variance for column Rainfall.

(d) Write statement(s) to compute mean , mode median for last 10 rows.

Python Pandas

1 Like

Answer

(a)

>>> wdf.min()
Output
Minimum values for each column:
minTemp         2.9
maxTemp         8.0
Rainfall       15.5
Evaporation     0.0
dtype: float64

(b)

>>> wdf.max(axis=1)
Output
Maximum values for each row:
0     24.3
1     26.9
2     23.4
3     39.8
4     17.6
5     18.2
6     21.1
7     18.3
8     20.8
9     22.8
10    25.2
11    28.5
12    29.1
13    30.9
14    31.2
15    34.4
16    33.8
17    30.0
18    32.4
19    33.4
20    33.4
dtype: float64

(c)

>>> wdf['Rainfall'].var()
Output
Variance for column Rainfall: 38.852999999999994

(d)

>>> last_10_rows = wdf.tail(10)
>>> last_10_rows.mean()
>>> last_10_rows.mode()
>>> last_10_rows.median()
Output
Mean for last 10 rows:
minTemp        17.78
maxTemp        29.60
Rainfall       30.97
Evaporation     0.20
dtype: float64

Mode for last 10 rows:
   minTemp  maxTemp  Rainfall  Evaporation
0     11.8     24.1      31.2          0.0
1     13.2     26.7      33.4          NaN
2     16.8     28.1       NaN          NaN
3     17.6     28.5       NaN          NaN
4     18.5     28.6       NaN          NaN
5     18.8     29.1       NaN          NaN
6     19.4     30.3       NaN          NaN
7     19.7     32.4       NaN          NaN
8     20.4     33.8       NaN          NaN
9     21.6     34.4       NaN          NaN

Median for last 10 rows:
minTemp        18.65
maxTemp        28.85
Rainfall       31.20
Evaporation     0.00
dtype: float64

Answered By

2 Likes


Related Questions