I have a pandas dataframe as follows:
foo bar
a b
1 10
2 25
3 9
I want to add a new column as follows:
foo bar baz
a b 0
1 10 1
2 25 1
3 9 1
Which is: if row['foo'] or row['bar] is numeric, then row['baz'] = 1 else 0
What I have so far is:
def some_function(row):
if row['foo']>=0 or row['bar']>=0:
return 1
return 0
df['baz'] = df.apply(lambda row: some_function(row), axis=1
But this doesn't work because the dtype is not int
.
I can't drop non-int
rows, because I need them in the dataframe.
Any idea how I can solve this?