I have some challenge in my work regarding working with pandas.
I have a pandas dataframe with columns Time, x, y, a, b
.
For simplicity, the dataframe has 5 records, from which 3 records are fully filled (Time, x,y,a,b
has data). Other 2 a,b
are empty. Time is unidirectional
I'd like to perform a calculation on some condition on Time
(lets say Time > 3
) and store result on a
and b
(lets say the functions are a=x^2, b=x^3
). The calculation of a,b
shall be performed in single function (I'm using lambda function). For example
Time x y a b
0.3 0 1 2.0 3.0
1.5 4 5 6.0 7.0
2.8 8 9 10.0 11.0
3.3 8 13 None None
4.5 3 17 None None
Shall be converted to
Time x y a b
0.3 0 1 2.0 3.0
1.5 4 5 6.0 7.0
2.8 8 9 10.0 11.0
3.3 8 13 64.0 512.0
4.5 3 17 9.0 27.0
Any assistance would be appreciated
Notes:
- number of records here are for simplicity and the code shall be general for every number of records.
- need that the code will be optimized for performance.