Page 64 - Informatics_Practices_Fliipbook_Class12
P. 64
0 2
1 5
2 2
3 1
4 4
5 2
6 1
7 5
dtype: int64
<ipython-input-109-ecdb615886f4>:2: FutureWarning: Dropping of nuisance columns in
DataFrame reductions (with 'numeric_only=None') is deprecated; in a future version
this will raise TypeError. Select only valid columns before calling the reduction.
print(groceryDF.min(axis=1))
Note that above warning has been caused by the presence of a mix of of string and numeric objects. Below, we find the
minimium values across the row by including only the numeric columns from the DataFrame:
>>> print("Minimum value in each row:")
>>> print(groceryDF[['Quantity', 'Price']].min(axis = 1))
Minimum value in each row:
0 2
1 5
2 2
3 1
4 4
5 2
6 1
7 5
dtype: int64
Next, we find the minimium values across the row by including only those columns from the DataFrame that comprise
of the string objects :
>>> print("Minimum value in each row:")
>>> print(groceryDF[['Product', 'Category']].min(axis = 1))
Minimum value in each row:
0 Bread
1 Food
2 Biscuit
3 Bourn-Vita
4 Hygiene
5 Brush
6 Detergent
7 Hygiene
dtype: object
You may be wondering why would someone find the minimum value across a row that includes attributes like Price
and Quantity. It is equally meaningless to compare the values in the Product and Category columns. However,
there are situations where comparison of data values across a row is indeed meaningful. For example, if the columns
were to indicate the marks obtained by the students in different subjects, it would make definite sense to the know
the maximum and minimum scores in a row, as illustrated below:
Next, let us construct a DataFrame comprising the marks obtained by 4 students in 5 subjects. First, we create a
dictionary marks that stores the marks of four students (RollNo: 301, 302, 303, 304) in different subjects (English,
Mathematics, Economics, History, and Psychology) as lists of scores.
>>> import pandas as pd
students = {'RollNo': [301, 302, 303, 304],
'English': [78, 68, 57, 45],
50 Touchpad Informatics Practices-XII

