Search code examples
pythonstringpandasdataframenonetype

Concatenating noneType and string value columns (pandas dataframes) results in "NaN"


I'm trying to concatenate two columns and the second column has a few noneType values. When I try to concatenate both the columns with the noneType values, the resulting column results in "NaN".

I tried to look around to see if I could find questions on this behavior, but I wasn't able to.

Here's what the table looked before concatenation:

enter image description here

Here's my code to join the two columns after my modifications:

new_table["name"] = new_table[0] + new_table[1]

Which results in this:

enter image description here

Why is does concatenation result in "NaN" and how can I fix it?


Solution

  • The most simple fix would be to replace None with empty string:

    new_table["name"] = new_table[0] + new_table[1].fillna('')