I have the following problem:
- A
DataFrame
containingcol1
with stringsA
,B
, orC
. - A second
col2
with anInteger
. - And three other columns
col3
,col4
andcol5
(these columns are also namedA
,B
, andC
).
Thus,
col1 - col2 - A (col3) - B (col4) - C (col5)
|--------------------------------------------
A 6
B 5
C 6
should obtain
col1 - col2 - A (col3) - B (col4) - C (col5)
|--------------------------------------------
A 6 6
B 5 5
C 6 6
Now I would like to go through each row and assign the integer in col2
to the column A, B or C based on the entry in col1
.
How do I achieve this?
df.withColumn()
I cannot use (or at least I do not know why) and the same holds for val df2 = df.map(x => x )
.
Looking forward to you help and thanks in advance!
Best, Ken