python - Map function across multi-column DataFrame -
given dataframe following
in [1]: import pandas pd in [2]: df = pd.dataframe({'x': [1, 2, 3, 4], 'y': [4, 3, 2, 1]}) i map row-wise function across columns
in [3]: df.map(lambda (x, y): x + y) and following
0 5 1 5 2 5 3 5 name: none, dtype: int64 is possible?
you can apply function row-wise setting axis=1
df.apply(lambda row: row.x + row.y, axis=1) out[145]: 0 5 1 5 2 5 3 5 dtype: int64
Comments
Post a Comment