select nan value - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: select nan value (/thread-23339.html) |
select nan value - fullstop - Dec-23-2019 I have a dataframe which have 2 columns. They have mutually exclusive nan in the cells. I mean the place where col1 is nan, col2 have some numerical value and vice versa. The situation is shown below df = pd.DataFrame({"A": [1, 'nan'], "B": ['nan', 2]})I would like to merge them into single columns with values taken from both, df = pd.DataFrame({"A": [1, 2]}) RE: select nan value - scidam - Dec-25-2019 Take a look at the following example: import pandas as pd df = pd.DataFrame({"A": [1, pd.np.nan], "B": [pd.np.nan, 2]}) df.loc[df.A.isna(), "C"] = df.B[df.A.isna()] df.loc[df.B.isna(), "C"] = df.A[df.B.isna()] |