0

I have a two seperate csv files I read into a pandas dataframe. I've already done a bit of cleaning and joined the tables by their date column. I have another column called 'ExerciseTime' and converted the imported time format of the time of day exercise was performed to a float format i.e. 22:30:00 (10:30 pm) to 22.5 (float value).

I am wanting to run train/test split analysis by comparing exercise time of day to quality of sleep (this is my Garmin connect data and Sleep cycle data). Currently there is very little accuracy/correlation but I suspect if I make the 'ExerciseTime' column into dummy variables by hour it may help. I am wanting to convert all values in the column to integer values (rounding up and down) and want to ignore any instances where there are nulls (days I didn't exercise). I currently am getting an error when I use the following formula:

JoinedTables = JoinedTables[JoinedTables.ExerciseTime.astype(int)]

What would be the best way to ignore the nulls and convert the float values to integers?

Also, if anyone knows of the best type model predictors to use on this type of data I would appreciate any ideas as I'm still new to this. I have other data points like "Total Exercise Duration", "If I consumed Alcohol before bed", "Type of Exercise that day", "Moon Phase that Day" that I would like to incorporate as well and see if there is any statistically significant impact on my sleep quality.

DEB
  • 241
  • 1
  • 2
  • 7

1 Answers1

2

pd.to_numeric(col, errors='coerce') should do the trick:

JoinedTables['ExerciseTime'] = pd.to_numeric(JoinedTables['ExerciseTime'], errors='coerce')
MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419
  • MaxU, the function allowed me to successfully create another column that brought over only the values from ExerciseTime that had values but the output still remained as float values. Any idea for how to change that? – DEB Oct 02 '17 at 20:00
  • @DomB, it's going to be `float` unless __all__ values can be convertedto integers. If there is at least one value that can't be converted to `int`, then it's going to be `float`. `int` dtype can't have `NaN` values ... – MaxU - stand with Ukraine Oct 02 '17 at 20:05