From 095d8107d804005bb6181a8280707e1fe79ee5f9 Mon Sep 17 00:00:00 2001 From: Ryan Missel Date: Fri, 29 Mar 2019 19:42:15 -0400 Subject: [PATCH] Vectorization example in pandas --- data_preparation/vectorization_ex.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 data_preparation/vectorization_ex.py diff --git a/data_preparation/vectorization_ex.py b/data_preparation/vectorization_ex.py new file mode 100644 index 0000000..331a70b --- /dev/null +++ b/data_preparation/vectorization_ex.py @@ -0,0 +1,18 @@ +import pandas as pd + +# read in CSV +df = pd.read_csv('cleaned/wellness.csv') + +# print out column uniques +print(df["Illness"].unique()) + +# make dictionary of unique values and their associated values +illness = {'No': 0, 'Slightly Off': 0.5, 'Yes': 1} + +# iterate through new column vectorize +df["IllnessNum"] = [illness[item] for item in df["Illness"]] + +df.to_csv('cleaned/wellness.csv') + +print(df["Illness"]) +print(df["IllnessNum"])