I want display dataframe with info from pandas df.info() this display to output in the command prompt but in html display None !!
Views.py
my_file = pd.read_csv(filename, engine='python')
data = pd.DataFrame(data=my_file)
mydict = {
"data": data.to_html(),
"dinfo": data.info(),
}
<div><h6 >Data </h6>{{data|safe}}</div>
<div><h6 >Data Info:</h6>{{dinfo|safe}}</div>
CodePudding user response:
Use StringIO:
import io
# Redirect output to a buffer
info = io.StringIO()
data.info(buf=info)
info.seek(0)
mydict = {
"data": data.to_html(),
"dinfo": info.read(),
}
Update
Is there a way to appear in a coordinated way on the page?
# pip install markdown
import markdown
mydict = {
"data": data.to_html(),
"dinfo": markdown.markdown(info.read()),
}
CodePudding user response:
if you want show any information on html page you should used render
from django.shortcuts import render
return render(request, 'index.html', context=mydict)
