Question: Suppose I have the following input dataframe,

df1,

```
 col1_1 | col2 | ....
AB0123  |      |
0678    |      |
AB0567  |      | 
0921    |      |
6752    |      |

```

and the following lookup dataframe

df2,

```
col1   | col2 | col3 |...
AB0123 |      |  abc |
AB0567 |      |  dfe | 
       |0678  |  ghi |
       |0921  |  jkl |
       |6752  |  mno |

```

Final output df,

```
 col1_1 | col1_or_col2 | col2....
AB0123  |     abc      |
0678    |     ghi      |
AB0567  |     dfe      |
0921    |     jkl      |
6752    |     mno      |

```

what I have in my mind is to create two temp columns in the output df and then making a separate function\* to generate col1\_or\_col2,

\*The function will check for each row and take the final not-empty value between temp\_col2 or temp\_col3

```
 col1  | temp_col1 | temp_col2 | col1_or_col2
AB0123 |   abc     |           |    abc
0678   |           |     ghi   |    ghi
AB0567 |   dfe     |           |    dfe
0921   |           |     jkl   |    jkl
6752   |           |     mno   |    mno

```

Is there a pandas function that I can use to solve the above problem efficiently?

Answer: 
In fact, you are close to the solution. The one you missed is to delete the curl source package.

So next should make the image reduce:

```
FROM debian:10.7

RUN apt-get update && \
    apt-get install --yes --no-install-recommends wget build-essential ca-certificates libcurl4 && \
    wget https://curl.se/download/curl-7.73.0.tar.gz && \
    tar -xvf curl-7.73.0.tar.gz && cd curl-7.73.0 && \
    ./configure && make && make install && \
    apt-get purge -y --auto-remove build-essential && \
    cd .. && rm -fr curl-7.73.0.tar.gz curl-7.73.0

```

Without Curl:

```
$ docker images abc:1
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
abc                 1                   d742bfdf5fa6        25 seconds ago      148MB

```

With curl & source package delete:

```
$ docker images abc:2
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
abc                 2                   afe3d404852a        27 minutes ago      151MB

```

Additional, if you delete apt cache with `rm -rf /var/lib/apt/lists/*` in Dockerfile, if will be smaller:

```
$ docker images abc:3
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
abc                 3                   5530b0e9b44f        2 minutes ago       134MB

```

Another solution maybe use [multistage-build](https://docs.docker.com/develop/develop-images/multistage-build/), you could use `./configure --prefix=xxx` to set a default install location, then `stage1` just used to build `curl`, while `stage2` copy the xxx folder from `stage1` to final image.
You should inclide `rm -rf /var/lib/apt/lists/*` into your RUN instruction to remove apt index files and might include `apt-get clean` to remove any other remaining package file.

Apart from that, you could also try using the *slim* image version, according to Docker Hub [debian:10.7-slim](https://hub.docker.com/layers/debian/library/debian/10.7-slim/images/sha256-d70fe252be511834ae8f685a90b0a658539c99c4a87f79c41831b09be0fee705?context=explore) is almost half size (~24Mb vs ~48Mb)

Finally, you can execute `du -h | sort -h` on a container from your generated image to find out where is the remaining space usage.