Git Product home page Git Product logo

Comments (4)

ofajardo avatar ofajardo commented on May 23, 2024

Read the csv using urllib2, write it to a file and then pass the path to the file to pyreadr. Something like this but instead od reading it, save to file:

https://stackoverflow.com/questions/16283799/how-to-read-a-csv-file-from-a-url-with-python

The underlying C library absolutely requires a file on disk, therefore pyreadr also requires it. I leave to the user to decide how to download the file.

from pyreadr.

MAGALLANESJoseManuel avatar MAGALLANESJoseManuel commented on May 23, 2024

NOT WORKING:

import pyreadr
from urllib.request import urlopen
link="https://github.com/EvansDataScience/data/raw/master/crime.RData"
response = urlopen(link)
result = pyreadr.read_r(response)
print(result.keys())

GIVES ME:

File "", line 10, in
result = pyreadr.read_r(response)

File "/Users/JoseManuel/anaconda3/envs/bookVisualDS/lib/python3.7/site-packages/pyreadr/pyreadr.py", line 40, in read_r
parser.parse(path)

File "pyreadr/librdata.pyx", line 117, in pyreadr.librdata.Parser.parse

File "pyreadr/librdata.pyx", line 134, in pyreadr.librdata.Parser.parse

AttributeError: 'HTTPResponse' object has no attribute 'encode'

from pyreadr.

ofajardo avatar ofajardo commented on May 23, 2024

As I mentioned before you have to write it to a file, something like this (not tested):

import pyreadr
from urllib.request import urlopen
link="https://github.com/EvansDataScience/data/raw/master/crime.RData"
response = urlopen(link)
fhandle = open('file.RData', 'wb')
fhandle.write(response)
fhandle.close()
result = pyreadr.read_r("file.RData")
print(result.keys())

from pyreadr.

ofajardo avatar ofajardo commented on May 23, 2024

OK, here the tested and working version:

import pyreadr
from urllib.request import urlopen
link="https://github.com/EvansDataScience/data/raw/master/crime.RData"
response = urlopen(link)
content = response.read()
fhandle = open('file.RData', 'wb')
fhandle.write(content)
fhandle.close()
result = pyreadr.read_r("file.RData")
print(result.keys())

from pyreadr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.