This is the second day of my participation in the August More text Challenge. For details, see: August More Text Challenge

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. The variance

1.1 Operating the Full Table

1.1.1 Calculate the variance of each column

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

result:

Physical store sales volume 110164.3 Online sales volume 92621.8 Cost 118.5 Price 93741.3 dType: Float64Copy the code

1.1.2 Calculate the variance of each row

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

result:

0     10558.250000
1    126019.666667
2    120818.000000
3      1130.250000
4    131161.666667
dtype: float64
Copy the code

1.2 Operate on a single row or column

1.2.1 Obtain the variance of a single column

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

result:

110164.3
Copy the code

1.2.2 Obtain the variance of a single row

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

result:

Physical store sales NaN Online sales NaN Cost NaN Price NaN DType: Float64Copy the code

1.3 Operate on multiple rows or columns

1.3.1 Obtain the variance of multiple columns

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

result:

Physical store sales 110164.3 Online sales 92621.8 dType: Float64Copy the code

1.3.2 Calculate the variance of multiple rows

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

result:

Physical store sales 242.0 Online sales 151250.0 Cost 242.0 Selling price 6160.5 dType: Float64Copy the code

2 Take the standard deviation

2.1 Performing Operations on the Full Table

2.1.1 Calculate the standard deviation of each column

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

result:

Physical store sales 331.910078 Online sales 304.338299 Cost 10.885771 Price 306.172010 dType: Float64Copy the code

2.1.2 Take the standard deviation of each row

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

result:

0    102.753345
1    354.992488
2    347.588838
3     33.619191
4    362.162487
dtype: float64
Copy the code

2.2 Operate on a single row or column

2.2.1 Calculate the standard deviation of a column

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

result:

331.910078183835825
Copy the code

2.2.2 Take the standard deviation of a row

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

result:

Physical store sales NaN Online sales NaN Cost NaN Price NaN DType: Float64Copy the code

2.3 Perform operations on multiple rows or columns

2.3.1 Calculate the standard deviation of multiple columns

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

result:

Physical store sales 331.910078 Online sales 304.338299 DType: Float64Copy the code

2.3.2 Standard deviation of multiple rows

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

result:

Physical store sales volume 15.556349 Online sales volume 388.908730 Cost 15.556349 Price 78.488853 dType: Float64Copy the code