You can do this with pandas:

    import pandas as pd
    from io import StringIO

    io = StringIO('''\
    id        A        B        C        D        E 
    100        1        0        0        0        0 
    101        0        1        1        0        0 
    102        1        0        0        0        0 
    103        0        0        0        1        1 
    ''')

    df = pd.read_csv(io, sep='\s+', index_col='id')
    val = df.apply(lambda row: ' '.join(df.columns[row==1]), axis=1)

Google for "boolean indexing" to see what's going on :)
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to