Browse Source

Vectorization example in pandas

master
Ryan Missel 5 years ago
parent
commit
095d8107d8
1 changed files with 18 additions and 0 deletions
  1. +18
    -0
      data_preparation/vectorization_ex.py

+ 18
- 0
data_preparation/vectorization_ex.py View File

@ -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"])

Loading…
Cancel
Save