In this note we will work on the same dataset as the main note in which we saw how to plot data. Now we will look at how to manipulate the data, starting by converting the units of one column of the dataset and then doing a calculation that uses two columns.
Below is an excerpt of the dataset.
import pandas as pdpigments = pd.read_csv('../../datasets/curated_abs_dataset.csv')display(pigments)
wavelength_nm
chlorophyll-a
chlorophyll-b
fucoxanthin
prasinoxanthin
0
800.2
0.0
0.000035
0.000629
0.000128
1
799.3
0.0
0.000000
0.000588
0.000166
2
798.5
0.0
0.000000
0.000599
0.000165
3
797.6
0.0
0.000000
0.000548
0.000216
4
796.7
0.0
0.000086
0.000491
0.000086
...
...
...
...
...
...
558
324.0
NaN
NaN
0.003124
0.002171
559
323.1
NaN
NaN
0.003056
0.002062
560
322.3
NaN
NaN
0.003098
0.002207
561
321.4
NaN
NaN
0.003092
0.002202
562
320.6
NaN
NaN
0.003042
0.002189
563 rows × 5 columns
1 Data manipulations
We often need to transform parts of our data - e.g.
Converting units
Calculating derived properties
Normalizing
Our dataset has the wavelength in nanometers, perhaps we would like to work with meters instead
This is an example of an element-wise operation - every element of pigments['wavelength_nm'] is multiplied by 10**(-9).
1.1 Exercise: Converting to photon energy
A more interesting unit conversion for this dataset would be to work with photon energy in eV, which can be computed with the formula
\[
E = \frac{1240}{\lambda}
\] Where \(E\) is the photon energy and \(\lambda\) is the wavelength in eV.
In the cell below the dataset is available in the variable pigments, Use the cell to make this conversion to eV.
1.2 Exercise: Mixture of pigments
We can approximate the absorbance of a mixture by using the equation
\[
A_{\mathrm{mixture}}(\lambda) = c_1 \cdot A_1(\lambda) + c_2 \cdot A_2(\lambda)
\] Where \(A\) are absorbances of each component of the mixture and \(c_i\) are proportions of each component. Use this to calculate the absorbance of a mixture of 70% chlorophyll-a and 30% chlorophyll-b