I have two columns and want to join values from one column to the other. I want to join values from column "A" to column "B", but at the and I want in column "B" for each cell to be with two lines if a cell from column "B" is not empty and only with value from column "A" if a cell in column "B" is empty.

Here is data frame

df

```
  A      B
  Nr.1  18b
  Nr.1  
  Nr.1  18c\nNr.2\n
  Nr.1  18d\nNr.1
  Nr.2  
  Nr.2  20a\n
  Nr.2  20a\nNr.2
  Nr.3  20b\nNr.2\n
  Nr.3  

```

So, at the and I want:

df

```
  A      B
  Nr.1  18b\nNr.1
  Nr.1  Nr.1
  Nr.1  18c\nNr.1
  Nr.1  18d\nNr.1
  Nr.2  Nr.2
  Nr.2  20a\nNr.2
  Nr.2  20a\nNr.2
  Nr.3  20b\nNr.2
  Nr.3  Nr.3

```

I tried with df['B'] = df[["B", "A"]].apply(lambda x: ''.join(x.dropna().astype(str)),axis=1) when I want to add values from column "A" and it works when the cell from column "B" ends with newline (\n)

When I do not have the newline at the end of string then I use df['B'] = df[["B", "A"]].apply(lambda x: '\n'.join(x.dropna().astype(str)),axis=1)

But the problem is when I already have two lines in the cell. I need to replace a value in the second line with the value from column "A", and at the end of the string should not be "\n".

Is it some elegant way to solve this?
I appreciate any help.