I have the code working and passing all but one test which fails with an error. The error happens in the assignment to ‘actual’ from the test:
class DataCleaningTestCase(unittest.TestCase):
def test_data_cleaning(self):
actual = int(time_series_visualizer.df.count())
expected = 1238
self.assertEqual(actual, expected, "Expected DataFrame count after cleaning to be 1238.")
And the error is:
TypeError: cannot convert the series to <class 'int'>
the return from df.count() is a Pandas Series and if I change the the line to :
actual = int(time_series_visualizer.df.count()[0])
It passes. Am I missing something or is this an error in the test code?
The df is set up as a global variable by the starter code and df.count() is a pandas method. It returns an array type (pandas series). I can change the test but these are FCC’s tests and should remain unchanged by me.
OK That works with the test as is, as long as you drop the date column. (Although I am not sure that should be required to test the count after data cleaning. It wouldn’t hurt to add the argument you suggested.)
Hello Sky020, I feel your initial suggestion make more sense. Otherwise in draw_bar_plot() session we have to reset the index. Unless this is design intention.
actual = int(time_series_visualizer.df.count(numeric_only=True))
Thank you so much for this post and mentioning dropping the date column! I didn’t feel right about changing the test code, either, even though it was frustrating that my code was creating the visualizations but kept from passing by that one error. I’m glad I kept looking for answers because this helped clarify the distinction between numerical and non-numerical data and the right tools to use (Numpy) with each type.