Ask Your Question
0

import CSV in python using jupyter notebook on cocalc cloud

asked 2017-08-16 16:40:27 +0100

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I want to import this https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data (CVS file) in my python script with the commands:

url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'class']
dataset = pandas.read_csv(url, names=names)

The problem is that it returns this error message:


URLError Traceback (most recent call last) <ipython-input-21-45b1e7974739> in <module>() 32 url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data" 33 names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'class'] ---> 34 dataset = pandas.read_csv(url, names=names)

/projects/sage/sage-7.6/local/lib/python2.7/site-packages/pandas/io/parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, skip_footer, doublequote, delim_whitespace, as_recarray, compact_ints, use_unsigned, low_memory, buffer_lines, memory_map, float_precision) 653 skip_blank_lines=skip_blank_lines) 654 --> 655 return _read(filepath_or_buffer, kwds) 656 657 parser_f.__name__ = name /projects/sage/sage-7.6/local/lib/python2.7/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds) 390 compression = _infer_compression(filepath_or_buffer, compression) 391 filepath_or_buffer, _, compression = get_filepath_or_buffer( --> 392 filepath_or_buffer, encoding, compression) 393 kwds['compression'] = compression 394 /projects/sage/sage-7.6/local/lib/python2.7/site-packages/pandas/io/common.py in get_filepath_or_buffer(filepath_or_buffer, encoding, compression) 184 if _is_url(filepath_or_buffer): 185 url = str(filepath_or_buffer) --> 186 req = _urlopen(url) 187 content_encoding = req.headers.get('Content-Encoding', None) 188 if content_encoding == 'gzip': /projects/sage/sage-7.6/local/lib/python/urllib2.pyc in urlopen(url, data, timeout, cafile, capath, cadefault, context) 152 else: 153 opener = _opener --> 154 return opener.open(url, data, timeout) 155 156 def install_opener(opener): /projects/sage/sage-7.6/local/lib/python/urllib2.pyc in open(self, fullurl, data, timeout) 427 req = meth(req) 428 --> 429 response = self._open(req, data) 430 431 # post-process response /projects/sage/sage-7.6/local/lib/python/urllib2.pyc in _open(self, req, data) 445 protocol = req.get_type() 446 result = self._call_chain(self.handle_open, protocol, protocol + --> 447 '_open', req) 448 if result: 449 return result /projects/sage/sage-7.6/local/lib/python/urllib2.pyc in _call_chain(self, chain, kind, meth_name, args) 405 func = getattr(handler, meth_name) 406 --> 407 result = func(args) 408 if result is not None: 409 return result /projects/sage/sage-7.6/local/lib/python/urllib2.pyc in https_open(self, req) 1239 def https_open(self, req): 1240 return self.do_open(httplib.HTTPSConnection, req, -> 1241 context=self._context) 1242 1243 https_request = AbstractHTTPHandler.do_request_ /projects/sage/sage-7.6/local/lib/python/urllib2.pyc in do_open(self, http_class, req, **http_conn_args) 1196 except socket.error, err: # XXX what error? 1197 h.close() -> 1198 raise URLError(err) 1199 else: 1200 try: URLError: <urlopen error="" [errno="" 110]="" connection="" timed="" out="">

What's the problem? How could I solve? I use a free account on CoCalc. If it takes time to upload and so not enough for my free account, how I can upload the file as worksheet and link it? What will be the link in the URL specification?

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-08-17 17:11:33 +0100

psp gravatar image

I found it! Just upload the file in the same folder of the project, and then you can refer to it just with its name and extension, without any other address specification. So in my specific case:

dataset = pandas.read_csv('name_of_file.extension', names=names)

and it works greatly. Remember to use ' ' inside which you should specifies the file name

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-08-16 16:40:27 +0100

Seen: 4,279 times

Last updated: Aug 16 '17