This article is participating in Python Theme Month. See [activities]

The table used in this article is as follows:

Let’s look at the original situation:

Import pandas as pd df = pd.read_excel(r 'c :\Users\admin\Desktop\ test.xlsx ') print(df)Copy the code

result:

Classified Goods Physical store Sales Volume Online Cost of sales Selling Price 0 Fruit Apple 34 234 12 45 1 Home appliance TV 56 784 34 156 2 home appliance refrigerator 78 345 24 785 3 Books Python from getting started to giving up 25 34 13 89 4 Fruit grapes 789 56 7 398Copy the code

1. Maximize

1.1 Operating the Full Table

1.1.1 Obtain the maximum value of each column

Df = pd.read_excel(r'C:\Users\admin\Desktop\ test.xlsx ') print(df.max())Copy the code

result:

Category fruit products Grape physical store sales 789 online sales 784 Cost 34 Price 785 dtype: objectCopy the code

1.1.2 Find the maximum value of each row

Df = pd.read_excel(r'C:\Users\admin\Desktop\ test.xlsx ') print(df.max(axis=1))Copy the code

result:

0    234
1    784
2    785
3     89
4    789
dtype: int64
Copy the code

1.2 Operate on a single row or column

1.2.1 Obtain the maximum value of a single column

Df = pd.read_excel(r'C:\Users\admin\Desktop\ test.xlsx ') print(df[' sales '].max())Copy the code

result:

789
Copy the code

1.2.2 Find the maximum value of a single row

Df = pd.read_excel(r'C:\Users\admin\Desktop\ test.xlsx ') print(df.iloc[[0]].max())Copy the code

result:

Category fruit products Apple physical store sales 34 online sales 234 Cost 12 Price 45 dtype: objectCopy the code

1.3 Operate on multiple rows or columns

1.3.1 Maximize the number of columns

Df = pd read_excel (r 'C: \ Users \ admin \ Desktop \ test. XLSX') print (df [[' entity shop sales, "online sales"]]. Max ())Copy the code

result:

Physical store sales 789 online sales 784 dtype: Int64Copy the code

1.3.2 Maximize multiple rows

Df = pd.read_excel(r'C:\Users\admin\Desktop\ test.xlsx ') print(df.iloc[[0, 1]].max())Copy the code

result:

Category fruit products Apple physical store sales 56 online sales 784 Cost 34 Price 156 dType: objectCopy the code

2 is the minimum

2.1 Performing Operations on the Full Table

2.1.1 Minimize each column

Df = pd.read_excel(r'C:\Users\admin\Desktop\ test.xlsx ') print(df.min())Copy the code

result:

Category books Goods Python from Getting started to giving up In-store sales 25 Online sales 34 Cost 7 Price 45 dType: ObjectCopy the code

2.1.2 Minimize each row

Df = pd.read_excel(r'C:\Users\admin\Desktop\ test.xlsx ') print(df.min(axis=1))Copy the code

result:

0    12
1    34
2    24
3    13
4     7
dtype: int64
Copy the code

2.2 Operate on a single row or column

2.2.1 Minimizing a column

Df = pd.read_excel(r'C:\Users\admin\Desktop\ test.xlsx ') print(df.iloc[[0]].min())Copy the code

result:

25
Copy the code

2.2.2 Minimizing a row

Df = pd.read_excel(r'C:\Users\admin\Desktop\ test.xlsx ') print(df.iloc[[0]].median())Copy the code

result:

Category fruit products Apple physical store sales 34 online sales 234 Cost 12 Price 45 dtype: objectCopy the code

2.3 Perform operations on multiple rows or columns

2.3.1 Minimizing multiple columns

Df = pd read_excel (r 'C: \ Users \ admin \ Desktop \ test. XLSX') print (df [[' entity shop sales, "online sales"]]. The min ())Copy the code

result:

Sales in stores 25 online 34 dtype: int64Copy the code

2.3.2 Minimizing multiple rows

Df = pd.read_excel(r'C:\Users\admin\Desktop\ test.xlsx ') print(df.iloc[[0, 1]].min())Copy the code

result:

Physical store sales 45.0 line classification Household appliances TV physical store sales 34 Online sales 234 Cost 12 Price 45 dType: objectCopy the code