Issue
I am trying to take the data from direct URL in python JupyterNotebook. but the error I am getting is really frustrating me .
Here is the Link which I am fetching:
https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data
I am simply using Jupyter Notebook function as:
from IPython.display import HTML
HTML('https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data')
The error I am getting is the Following:
TypeError Traceback (most recent call last)
<ipython-input-15-0a8be2c0a7c6> in <module>
1 from IPython.display import HTML
----> 2 HTML('https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data')
C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\display.py in __init__(self, data, url, filename, metadata)
693 if warn():
694 warnings.warn("Consider using IPython.display.IFrame instead")
--> 695 super(HTML, self).__init__(data=data, url=url, filename=filename, metadata=metadata)
696
697 def _repr_html_(self):
C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\display.py in __init__(self, data, url, filename, metadata)
619
620 self.reload()
--> 621 self._check_data()
622
623 def __repr__(self):
C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\display.py in _check_data(self)
668 def _check_data(self):
669 if self.data is not None and not isinstance(self.data, str):
--> 670 raise TypeError("%s expects text, not %r" % (self.__class__.__name__, self.data))
671
672 class Pretty(TextDisplayObject):
TypeError: HTML expects text, not b'5.1,3.5,1.4,0.2,Iris-setosa\n4.9,3.0,1.4,0.2,Iris-setosa\n4.7,3.2,1.3,0.2,Iris-setosa\n4.6, ....
Any Help is really appreciated.
Solution
The error is due to the fact that HTML()
dosent expect CSV.
Use pandas read_csv
to easily and conveniently read the CSV file:
import pandas as pd
data = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data')
print(data)
Output:
5.1 3.5 1.4 0.2 Iris-setosa
0 4.9 3.0 1.4 0.2 Iris-setosa
1 4.7 3.2 1.3 0.2 Iris-setosa
2 4.6 3.1 1.5 0.2 Iris-setosa
3 5.0 3.6 1.4 0.2 Iris-setosa
4 5.4 3.9 1.7 0.4 Iris-setosa
.. ... ... ... ... ...
144 6.7 3.0 5.2 2.3 Iris-virginica
145 6.3 2.5 5.0 1.9 Iris-virginica
146 6.5 3.0 5.2 2.0 Iris-virginica
147 6.2 3.4 5.4 2.3 Iris-virginica
148 5.9 3.0 5.1 1.8 Iris-virginica
Answered By - Aviv Yaniv
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.