Data Analysis with Python Projects - Page View Time Series Visualizer

Tell us what’s happening:

For some reason i don’t understand i get an error in the cleaning data test of the testmodule. The error i get is this:

ERROR: test_data_cleaning (test_module.DataCleaningTestCase)

Traceback (most recent call last):
File “/home/runner/boilerplate-page-view-time-series-visualizer-1/test_module.py”, line 7, in test_data_cleaning
actual = int(time_series_visualizer.df.count(numeric_only=True))
File “/home/runner/boilerplate-page-view-time-series-visualizer-1/.pythonlibs/lib/python3.10/site-packages/pandas/core/series.py”, line 247, in wrapper
raise TypeError(f"cannot convert the series to {converter}")
TypeError: cannot convert the series to <class ‘int’>

What i can’t comprehend is that i’ve looked into the test file to see what were the expected values and all. After printing the count of the dataframe i’ve cleaned, it matches the expected result:
image
(The piece of the test code)
class DataCleaningTestCase(unittest.TestCase):
def test_data_cleaning(self):
actual = int(time_series_visualizer.df.count(numeric_only=True))
expected = 1238
self.assertEqual(actual, expected, “Expected DataFrame count after cleaning to be 1238.”)

and the error says something about converting to int type but the type of df.count() is already an int

Your code so far

maskclean1 = (df[‘value’] >= df[‘value’].quantile(0.025))
maskclean2 = (df[‘value’] <= df[‘value’].quantile(0.975))
print(df[‘value’].quantile(0.025))
df = df[maskclean1 & maskclean2]
print(df.count(numeric_only=True))
type(df.count(numeric_only=True))

Link to the whole code: boilerplate-page-view-time-series-visualizer (1) - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 OPR/106.0.0.0

Challenge Information:

Data Analysis with Python Projects - Page View Time Series Visualizer

The problem is when you are printing your df to test, yes it’s correct. But later in your program you change it, instead of making a copy first.

You should have had this instruction in the boilerplate code:

def draw_bar_plot():
    # Copy and modify data for monthly bar plot
    df_bar = None

    # Draw bar plot

It means to make a new copy of the df to work on using this df_bar variable.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.