Created
May 13, 2023 21:16
-
-
Save jmccardle/9457ac828f7a5d77872fe09c901322a7 to your computer and use it in GitHub Desktop.
This file contains 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 region(row): | |
#print(row) | |
state = row["state"] | |
if state in ("FL", "GA"): return "South" | |
elif state in ("CA", "WA"): return "West" | |
elif state in ("MT", "MN"): return "Central" | |
elif state in ("NY", "ME"): return "North" | |
else: return "Unknown" | |
#example data since I don't have your db. | |
df = pd.DataFrame(data={"d": [1,4,9,16], "state":["NY", "FL", "CA", "MT"]}) | |
regions = df.apply(region, axis=1) | |
df["region"] = regions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment