datafest competition 2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.7 KiB

  1. import pandas as pd
  2. def vectorize_mult(df, column, dictionary):
  3. """
  4. Changes all the categorical values into its respective
  5. number in the dictionary and then saves it in the DF
  6. :param df: dataframe
  7. :param column: column name
  8. :param dictionary: alterations to make
  9. """
  10. newCol = column + "Num"
  11. df[newCol] = df[column].map(dictionary)
  12. class WellnessCSV:
  13. def __init__(self):
  14. self.file = "data/wellness.csv"
  15. self.end = "cleaned/notnormalized_with_0NaN_wellness.csv"
  16. def vectorize(self):
  17. df = pd.read_csv(self.file)
  18. # Vectorizing appropriate data
  19. vectorize_mult(df, "Pain", {"No": 0, "Yes": 1})
  20. vectorize_mult(df, "Illness", {"No": 0, "Slightly Off": 0.5, "Yes": 1})
  21. vectorize_mult(df, "Menstruation", {"No": 0, "Yes": 1})
  22. vectorize_mult(df, "Nutrition", {"Poor": 0, "Okay": 0.5, "Excellent": 1})
  23. vectorize_mult(df, "NutritionAdjustment", {"No": 0, "Yes": 1})
  24. vectorize_mult(df, "USGMeasurement", {"No": 0, "Yes": 1})
  25. readiness = []
  26. for i, value in df["TrainingReadiness"].iteritems():
  27. value = value.split("%")[0]
  28. value = int(value) * (1/100)
  29. readiness.append(value)
  30. df["TrainingReadinessNum"] = readiness
  31. # Filling in NaNs for appropriate layers where they won't make a statistical difference
  32. df["MenstruationNum"] = df["MenstruationNum"].fillna(0)
  33. df["USGMeasurementNum"] = df["USGMeasurementNum"].fillna(0)
  34. df["NutritionNum"] = df["MenstruationNum"].fillna(0)
  35. df["NutritionAdjustmentNum"] = df["NutritionAdjustmentNum"].fillna(0)
  36. # Saving the df to the "cleaned" CSV
  37. df.to_csv(self.end)
  38. cls = WellnessCSV()
  39. cls.vectorize()