I have a dataframe as shown below:
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
from functools import reduce
import pandas as pd
from numpy import uint8, logical_or
df = pd.read_table(StringIO("""a b c
1 0 0
1 1 1
0 1 1
1 1 0"""), sep="\s+", dtype=uint8, header=0)
How do I columnwise reduce the dataframe?
Currently I just put all the vectors in a list and reduce it, but this cannot be the most pandastic way of doing it:
gene_vectors = [df[v] for v in df]
print(reduce(logical_or, gene_vectors))
Any alternatives?
I believe this is the "pandastic" way to achieve this
df.apply(lambda x: reduce(logical_or,x), axis=1)
although there might be other routes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With