In pandas DataFrame, i need to create result column, that is result of comparison of two columns.
If in column SECOND - NaN, then in result column - FIRST.
If in column SECOND - not NaN, then in result column - SECOND.
first | second | |
---|---|---|
0 | test | Nan |
1 | test2 | test3 |
->
result | first | second | |
---|---|---|---|
0 | test | test | Nan |
1 | test3 | test2 | test3 |
df = pandas.read_csv(file)
df["result"] = df["second"] if df["second"] else df["first"]