I have a Dataframe df like this:
A B C D
2 1 O s h
4 2 P
7 3 Q
9 4 R h m
I have a function f to compute C and D based on B for a string:
def f(p):
return p+'k', p+'n'
How can I fill in the missing values for lines 4 and 7 by applying the f function to the Dataframe?
The expected result is as follows:
A B C D
2 1 O s h
4 2 P Pk Pn
7 3 Q Qk Qn
9 4 R h m
The function f should be used since the actual function is very complex. In addition, this function should only apply to strings without C and D
source
share