Created
October 21, 2022 11:19
-
-
Save datagy/f1703c61d47b2b923ee172e05d99f178 to your computer and use it in GitHub Desktop.
Using an IF Statement in Pandas
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
| # Using if Statements in Python | |
| import pandas as pd | |
| df = pd.DataFrame({ | |
| 'Name': ['Nik', 'Kate', 'Evan'], | |
| 'Location': ['Toronto, ON', 'Atlanta, GA', 'Portland, OR'], | |
| 'Total': [99.99, 125.65, 33.43] | |
| }) | |
| df['Over 100'] = ['Yes' if Total > 100 else 'No' for Total in df['Total']] | |
| print(df) | |
| # Returns: | |
| # Name Location Total Over 100 | |
| # 0 Nik Toronto, ON 99.99 No | |
| # 1 Kate Atlanta, GA 125.65 Yes | |
| # 2 Evan Portland, OR 33.43 No |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment