Last active
May 16, 2016 09:50
-
-
Save godber/fd2e9793d984db553ca066a99462f7ea to your computer and use it in GitHub Desktop.
Pandas Operate on Multiple Rows with Boolean Operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| def r(row): | |
| if row['lat'] < 5: | |
| return row['data'] | |
| elif row['lat'] >= 5: | |
| return 10 * row['data'] | |
| df = pd.DataFrame({ 'data': range(10), 'lat': range(10)}, columns=["lat", "data"]) | |
| print(df) | |
| df['adj'] = df.apply(r, axis=1) | |
| print(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about: