Pandas Unit Convert Using Pandas

9/7/2020

pandas-unit-convert-Using-Pandas

Unit Conversion Trick

We may also want to do math on pandas data. So to do this I thought we could convert our units.

In [1]: %matplotlib inline

import pandas as pd

import numpy as np

import matplotlib.pylab as plt

from scipy import stats

from matplotlib.backends.backend_pdf import PdfPages

In [2]: df_well_data=pd.read_csv('well_data.csv')

I did not talk about units except for Arsenic. But we have the following elements and their units.

'Si':ppb,

'P':ppm,

'S':ppb,

'Ca':ppb,

'Fe':ppm,

'Ba':ppb,

'Na':ppm,

'Mg':ppb,

'K':ppb,

'Mn':ppm,

'As':ppb,

'Sr':ppb,

'F':ppm,

'Cl':ppm,

'SO4':ppm,

'Br':ppm

Remember back to chemistry........

ppm=parts per million = milligrams per liter = mg/l

ppb=parts per billions = micrograms per liter = ug/l

we can convert between these two. 1000 ppb = 1 ppm or to convert

1

mg

l

?

1000u

m

= 1000

ug

l

localhost:8888/nbconvert/html/python/fall20/BigDataPython/pandas-unit-convert-Using-Pandas.ipynb?download=false

1/13

9/7/2020

pandas-unit-convert-Using-Pandas

So lets convert As to ppm. It is now ppb. We could just print it first

localhost:8888/nbconvert/html/python/fall20/BigDataPython/pandas-unit-convert-Using-Pandas.ipynb?download=false

2/13

9/7/2020

pandas-unit-convert-Using-Pandas

In [3]: print(df_well_data.As/1000)

localhost:8888/nbconvert/html/python/fall20/BigDataPython/pandas-unit-convert-Using-Pandas.ipynb?download=false

3/13

9/7/2020

pandas-unit-convert-Using-Pandas

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

NaN

NaN

NaN

0.078977

NaN

NaN

0.028071

NaN

0.096886

0.080627

NaN

0.077007

0.039250

0.131249

0.000177

NaN

NaN

0.147639

NaN

0.052427

NaN

NaN

NaN

NaN

0.005365

NaN

NaN

NaN

0.053098

NaN

...

0.165760

NaN

0.000180

0.093650

0.101430

NaN

NaN

0.087900

NaN

0.001170

0.085260

0.055750

0.026960

NaN

NaN

NaN

NaN

NaN

NaN

0.000120

0.031690

0.009150

0.026980

0.021740

0.117820

0.000130

localhost:8888/nbconvert/html/python/fall20/BigDataPython/pandas-unit-convert-Using-Pandas.ipynb?download=false

4/13

9/7/2020

pandas-unit-convert-Using-Pandas

755

0.017390

756

0.112370

757

0.248930

758

NaN

Name: As, Length: 759, dtype: float64

that didn't change it. We could set a new column.

In [4]: df_well_data['As-ppm']=df_well_data.As/1000

In [5]: print(df_well_data.describe())

count

mean

std

min

25%

50%

75%

max

Well_ID

759.000000

6417.088274

6695.778189

2.000000

4116.000000

5928.000000

8134.500000

141499.000000

Lat

759.000000

23.789249

0.578493

22.780000

23.285000

23.790000

24.300000

24.770000

count

mean

std

min

25%

50%

75%

max

P

407.000000

0.809323

0.902860

0.008210

0.151957

0.507850

1.189271

5.477616

count

mean

std

min

25%

50%

75%

max

...

...

...

...

...

...

...

...

...

Mg

407.000000

20.487685

11.359487

2.490000

14.020000

18.250000

24.780000

104.545670

K

343.000000

5068.337278

5566.741424

18.855854

2804.793027

3563.100000

4979.045000

44273.150000

count

mean

std

min

25%

50%

75%

max

Sr

407.000000

186.770328

90.501136

34.470000

119.685000

174.617542

233.535000

681.287906

F

413.000000

0.216924

0.194702

-0.010200

0.113000

0.166700

0.239700

1.595800

Cl

411.000000

42.371061

34.464444

0.226100

18.931200

31.298100

52.962050

217.525000

S

407.000000

3407.292389

5364.247733

-41.390000

149.635000

1220.877945

4341.695000

45035.460000

Lon

759.000000

90.641199

0.578800

89.610000

90.155000

90.650000

91.130000

91.650000

Depth

759.000000

65.554677

42.186161

0.000000

45.000000

50.000000

70.000000

523.000000

Ca

407.000000

41129.291921

20161.130827

3577.160000

26996.273955

40166.830000

52976.458285

116040.620000

Si

407.000000

40101.151444

10117.680290

12605.576700

33200.310900

40021.490000

45369.825000

70304.057950

Fe

407.000000

5.556200

5.153779

-0.003680

1.706806

3.931310

8.531585

30.192230

Mn

407.000000

1.309343

0.978969

0.000000

0.545000

1.183136

1.850000

6.271782

SO4

397.000000

9.300930

14.287154

0.120000

0.407100

3.344400

11.973300

125.317000

Ba

407.000000

89.078507

54.172650

5.630000

53.423976

79.674488

113.711543

293.440000

As

407.000000

89.688641

101.530582

0.000000

14.026849

54.400000

129.433314

700.890000

Br

405.000000

0.056895

0.087262

0.005800

0.019300

0.032700

0.053800

0.994800

\

\

\

As-ppm

407.000000

0.089689

0.101531

0.000000

0.014027

0.054400

0.129433

0.700890

[8 rows x 21 columns]

localhost:8888/nbconvert/html/python/fall20/BigDataPython/pandas-unit-convert-Using-Pandas.ipynb?download=false

5/13

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download