Visualizador de vistas de página en determinados períodos de tiempo (TypeError: cannot convert the series to <class 'int'>)

hola desde hace un tiempo eh tenido este error y no eh podido arreglarlo.
parece ser que el problema es el modulo de prueba, imprimo el dataframe y solo tiene una columna y el índice el numero de índice coincide con el del modulo de prueba ,probe cambiando la forma en que se manejaba la línea 7 en el modulo de prueba y corrió muy bien

ERROR: test_data_cleaning (test_module.DataCleaningTestCase)

Traceback (most recent call last):
File “/home/runner/boilerplate-page-view-time-series-visualizer/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/.pythonlibs/lib/python3.10/site-packages/pandas/core/series.py”, line 230, in wrapper
raise TypeError(f"cannot convert the series to {converter}")
TypeError: cannot convert the series to <class ‘int’>


Ran 11 tests in 10.857s

FAILED (errors=1)

You’re on the right track checking if the df is 1 column.

The problem probably isn’t the test, you will never need to edit the test to pass (even if sometimes it seems like that is the case). The tests do require specific formats.

Can you share a link to the replit or copy/paste your code here?

esta es una parte del código

# Import data (Make sure to parse dates. Consider setting index column to 'date'.) 
df = pd.read_csv('fcc-forum-pageviews.csv',parse_dates=["date"],index_col="date")
#df.set_index('date', inplace=True)

# Clean data
df = df[(df['value'] >= df['value'].quantile(0.025)) & 
        (df['value'] <= df['value'].quantile(0.975))]

print(df)

también te dejo el link por si quieres revisarlo a fondo
time_series_visualizer.py - boilerplate-page-view-time-series-visualizer - Replit

You’re printing off the df after cleaning it and it looks good. However, the problem is created here:

def draw_bar_plot():
    # Copy and modify data for monthly bar plot
    df.index = pd.to_datetime(df.index)
    df['year'] = df.index.year
    df['month'] = df.index.month
    df_bar = df.groupby(['year', 'month'])['value'].mean()
    df_bar = df_bar.unstack()

The tests run after all your functions have executed. Add print(df) after this block of code and see what it looks like.

1 Like

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