2

My code below is a pandas dataframe, I've tried transcypt and flask to view this code in my browser, but have had errors. Any help would be greatly appreciated.

import pandas as pd

columns = ['cap', 'title', 'price']
df = pd.read_csv('asdawhiskey.csv', names=columns)

items = df[df['cap'] == '70cl']

print(items.to_html()) 
6
  • You can use Django framework, but if you want to just print() something to browser, it would be hard to do. Edit: you can ask new question and add errors that you get when trying Flask. Commented Jul 16, 2020 at 19:21
  • "I've tried transcypt and flask to view this code in my browser, but have had errors" -> What errors were you getting? Something like this seems fairly easy to set up in Flask Commented Jul 16, 2020 at 19:23
  • Firstly thank you for your response. The code creates a html table format in my terminal but I want to be able to physically see the table in a browser, will Django framework achieve this? Commented Jul 16, 2020 at 19:25
  • 1
    Could you just save the output to file (using > redirection) and open that file? Commented Jul 16, 2020 at 19:28
  • Have you tried brython? Commented Jul 16, 2020 at 19:41

2 Answers 2

3

Try Streamlit. https://streamlit.io You don't have to write a single line of html

import streamlit as st
import pandas as pd

columns = ['cap', 'title', 'price']
df = pd.read_csv('asdawhiskey.csv', names=columns)

items = df[df['cap'] == '70cl']

st.write(items)

Then run streamlit run example.py

Sign up to request clarification or add additional context in comments.

6 Comments

Hey Naveen, Please correct the function name for writing
Fixed it, sorry for the typo
That looks promising, I will try this and get back too you, thankyou.
I'm currently getting an error when running the code, in the terminal I am getting Import error: no module named 'urllib3' all my other code seems to work okay still, but when I add streamlit I get this error?
try installing that package using 'pip install urllib3'. Also have you installed streamlit? If not install it using 'pip install streamlit'
|
1

Is it possible to run python code in a web browser ? - Yes, It is now possible with the help of PyScript. Say thanks to this framework that allows users to create rich Python applications in the browser

There is no installation required. We can just use the PyScript assets served on https://pyscript.net/

Live Demo :

<html>
  <head>
    <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
    <script defer src="https://pyscript.net/latest/pyscript.js"></script>
  </head>
  <body> <py-script> print('Hello, World!') </py-script> </body>
</html>

Note (As per the current official documentation) :

PyScript is very alpha and under heavy development. There are many known issues, from usability to loading times, and you should expect things to change often. We encourage people to play and explore with PyScript, but at this time we do not recommend using it for production.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.