I have a data frame pandas(v 0.20.3):
df = pd.DataFrame({'coname1': ['Apple','Yahoo'], 'coname2':['Apple', 'Google']})
df['eq'] = df.apply(lambda row: row['coname1'] == row['coname2'], axis=1).astype(bool)
coname1 coname2 eq
0 Apple Apple True
1 Yahoo Google False
If I would like to replace True/Falsewith 'Yes'/'No', I could run this:
df.replace({
True: 'Yes',
False: 'No'
})
coname1 coname2 eq
0 Apple Apple Yes
1 Yahoo Google No
Which seems to be doing its job. However, if the data frame is only one row with a value 0/1in the column, it will also be replaced because it is treated as a logical one.
df1 = pd.DataFrame({'coname1': [1], 'coname2':['Google'], 'coname3':[777]})
df1['eq'] = True
coname1 coname2 coname3 eq
0 1 Google 777 True
df1.replace({
True: 'Yes',
False: 'No'
})
coname1 coname2 coname3 eq
0 Yes Google 777 Yes
I would like to display True/Falsein Yes/Nofor all the columns in the data frame that matter dtype bool.
How to report pandas, in order to run the True / False map for arbitrary rows only for columns with dtype boolno explicit column names, since I may not know them in advance