16

I try to run the below codes but I have a problem in showing the results. also, I use pycharm IDE.

from fastai.text import *

data = pd.read_csv("data_elonmusk.csv",  encoding='latin1')
data.head()

data = (TextList.from_df(data, cols='Tweet')
                .split_by_rand_pct(0.1)
                .label_for_lm()
                .databunch(bs=48))

data.show_batch()

The output while I run the line "data.show_batch()" is:

IPython.core.display.HTML object
tripleee
  • 175,061
  • 34
  • 275
  • 318
Siamak Abdi
  • 191
  • 1
  • 1
  • 10

6 Answers6

8

If you don't want to work within a Jupyter Notebook you can save data as an HTML file and open it in a browser.

with open("data.html", "w") as file:
    file.write(data)
4

You can only render HTML in a browser and not in a Python console/editor environment.

Hence it works in Jupiter notebook, Jupyter Lab, etc.

At best you call .data to see HTML, but again it will not render.

Arpit-Gole
  • 365
  • 2
  • 6
2

I solved my problem by running the codes on Jupiter Notebook.

Siamak Abdi
  • 191
  • 1
  • 1
  • 10
2

You could add this code after data.show_batch():

plt.show()

yelou
  • 21
  • 2
1

Another option besides writing it do a file is to use an HTML parser in Python to programatically edit the HTML. The most commonly used tool in Python is beautifulsoup. You can install it via

pip install beautifulsoup4

Then in your program you could do

from bs4 import BeautifulSoup

html_string = data.show_batch().data
soup = BeautifulSoup(html_string)
# do some manipulation to the parsed HTML object
# then do whatever else you want with the object
Greg
  • 5,422
  • 1
  • 27
  • 32
1

Just use the data component of HTML Object.

with open("data.html", "w") as file:
    file.write(data.data)
user3278869
  • 3
  • 1
  • 5