Table Operations#

pymeasurement can be used with Pandas DataFrames to perform precision-based uncertainty calculations on tables of data.

Original Data Table

Mass (± 0.001 kg)

Average Acceleration (m/s^2)

Average Acceleration Percent Uncertainty (%)

2.5563

9.2

1.7

2.235

7.85

1.4

2.324

8.44

1.1

2.584

10.5

1.5

2.768

8.38

1.2

2.956

7.35

1.3

In order to acheive this, the DataFrame is converted into Measurement objects for calculations using the below.

All data can be normalized in this step as well.

>>> import pandas as pd
>>> df = pd.read_excel('example.xlsx')
>>> from pymeasurement import Measurement as M
>>> converted = pd.DataFrame()
>>> converted['Mass (± 0.001 kg)'] = M.importColumn(df['Mass (± 0.001 kg)'], d=True, un='kg', decimals=3)
>>> converted['Average Acceleration (m/s^2)'] = M.importColumn(df['Average Acceleration (m/s^2)'], uncertaintyColumn=df['Average Acceleration Percent Uncertainty (%)'], df=df, up=True, un='m/s^2', decimals=2)

Converted Data Table

Mass (± 0.001 kg)

Average Acceleration (m/s^2)

2.556 +/- 0.001 kg

9.20 +/- 1.7% m/s^2

2.235 +/- 0.001 kg

7.85 +/- 1.4% m/s^2

2.324 +/- 0.001 kg

8.44 +/- 1.1% m/s^2

2.584 +/- 0.001 kg

10.50 +/- 1.5% m/s^2

2.768 +/- 0.001 kg

8.38 +/- 1.2% m/s^2

2.956 +/- 0.001 kg

7.35 +/- 1.3% m/s^2

Now calculations can easily be performed on the DataFrame using the Measurement objects.

>>> converted['Force (N)'] = converted['Mass (± 0.001 kg)'] * converted['Average Acceleration (m/s^2)']

Calculated Data Table

Mass (± 0.001 kg)

Average Acceleration (m/s^2)

2.556 +/- 0.001 kg

9.20 +/- 1.7% m/s^2

2.235 +/- 0.001 kg

7.85 +/- 1.4% m/s^2

2.324 +/- 0.001 kg

8.44 +/- 1.1% m/s^2

2.584 +/- 0.001 kg

10.50 +/- 1.5% m/s^2

2.768 +/- 0.001 kg

8.38 +/- 1.2% m/s^2

2.956 +/- 0.001 kg

7.35 +/- 1.3% m/s^2

Once the calculations are complete, the DataFrame can be converted back into numeric types using the below.

>>> final_table = converted.copy()
>>> M.exportColumn(final_table, converted['Mass (± 0.001 kg)'], addUncertainty=False)
>>> M.exportColumn(final_table, converted['Average Acceleration (m/s^2)'])
>>> M.exportColumn(final_table, converted['Force (N)'], asPercent=False)

Mass (± 0.001 kg)

Average Acceleration (m/s^2)

Average Acceleration Percent Uncertainty (%)

Force (N)

Force Absolute Uncertainty (N)

2.556

9.2

1.7

23.5

0.4

2.235

7.85

1.4

17.5

0.3

2.324

8.44

1.1

19.6

0.2

2.584

10.5

1.5

27.13

0.42

2.768

8.38

1.2

23.2

0.3

2.956

7.35

1.3

21.7

0.3