Im a beginner in Data Science and was wondering if I can make a column in a certain dataframe that always updates when a given cell has its values changed.
As an example:
In the famous Iris df, we have some numeric columns, such as: SepalLengthCm andSepalWidthCm.
Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm Species
0 1 5.1 3.5 1.4 0.2 Iris-setosa
1 2 90.0 3.0 1.4 0.2 Iris-setosa
2 3 4.7 3.2 1.3 0.2 Iris-setosa
3 4 4.6 3.1 1.5 0.2 Iris-setosa
4 5 5.0 3.6 1.4 0.2 Iris-setosa
... ... ... ... ... ... ... ...
145 146 6.7 3.0 5.2 2.3 Iris-virginica
146 147 6.3 2.5 5.0 1.9 Iris-virginica
147 148 6.5 3.0 5.2 2.0 Iris-virginica
148 149 6.2 3.4 5.4 2.3 Iris-virginica
149 150 5.9 3.0 5.1 1.8 Iris-virginica
If i, for some reason, wish to create a new column that sums these two columns, I can do:
df['Sum'] = df['SepalLengthCm']+df['SepalWidthCm']
But when a value in these two columns is changed, the sum doesn`t follow recalculating.
Is it possible to create a function that is aware of changes in columns?