'Displaying data from a column of my dataframe in a web page

I want to display the rows of a column of my dataframe in a web page. I get an error on the following line:

return render(requete, 'analyse/index.html', context={'data': df['EXTERNAL_DATA2'].tolist()})

Below is the error that is displayed:

TypeError: list indices must be integers or slices, not str



Solution 1:[1]

Probably (based on the error message) df is not a pandas.DataFrame object but a list. Depending on its inner structure you might try (untested)

df2 = pandas.DataFrame(df)

return render(requete, 'analyse/index.html', context={'data': df2['EXTERNAL_DATA2'].tolist()})

In general you should debug data-related problems outside of your web application. Django and randering your data to html only adds unnecessary complexity here. I would recommend, to use jupyter or ipython to interactively explore your data only then process it in the webapp.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1