I have pandas dataframe as below,
Location Loc_Code Service_Onroad Service_Cargo
0 Bangalore Vadakara01 Common Common
1 Bangalore Hosdung02 Transit Transit
2 Bangalore Hosdung02 Common Transit
3 Bangalore Kozhikode Common Common
4 Bangalore Malappuram Transit Transit
5 Bangalore Kalpetta09 Common Common
6 Bangalore Kasargod Transit Transit
7 Bangalore Maananthavaadi Common Common
8 Bangalore Alattur Transit Transit
9 Bangalore Pazhani Common NaN
10 Bangalore Ernakulam Transit Transit
11 Bangalore Aluva Connect Connect
12 Bangalore Kochi Common Transit
13 Bangalore Kochi Transit Transit
14 Bangalore Paravoor Common Common
15 Bangalore Chaavakkaad Transit Transit
16 Bangalore Tirur Transit Transit
17 Bangalore Mannaarkkad Common Common
18 Bangalore Koramangala NaN NaN
19 Bangalore Rajna NaN NaN
20 Bangalore Palai09 Interconnect NaN
21 Bangalore Palai09 Common NaN
I wanted to compare Service_Onroad
with Service_Cargo
and if it matches, I wanted to write it as "Matched
" in new Column (i.e Results). And if it doesn't match, I wanted to write it as "Not Matched
". In any of the column (Service_Onroad
& Service_Cargo
) if the value is NaN then I do not wanted to write anything there.
How can we do the comparison ? I believe that in Pandas, Nan is also taken as string for the comparison which results in "FALSE"? So how do we rule this out?