I"m trying to read a csv-file from given URL, using Python 3.x:
import pandas as pd import requests url = "https://github.com/cs109/2014_data/blob/master/countries.csv" s = requests.get(url).content c = pd.read_csv(s)
I have the following error
"Expected file path name or file-like object, got <class "bytes"> type"
How can I fix this? I"m using Python 3.4
In the latest version of pandas (
0.19.2) you can directly pass the url
import pandas as pd url="https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv" c=pd.read_csv(url)
UPDATE: From pandas
0.19.2 you can now just pass
read_csv() the url directly, although that will fail if it requires authentication.
For older pandas versions, or if you need authentication, or for any other HTTP-fault-tolerant reason:
pandas.read_csv with a file-like object as the first argument.
If you want to read the csv from a string, you can use
For the URL
https://github.com/cs109/2014_data/blob/master/countries.csv, you get
html response, not raw csv; you should use the url given by the
Raw link in the github page for getting raw csv response , which is
import pandas as pd import io import requests url="https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv" s=requests.get(url).content c=pd.read_csv(io.StringIO(s.decode("utf-8")))
in Python 2.x, the string-buffer object was
For courses in business intelligence or decision support systems. A managerial approach to understanding business intelligence systems. To help future managers use and understand analytics, Business...
A Problem-Solver’s Guide to Building Real-World Intelligent Systems. Data is the new oil and Machine Learning is a powerful concept and framework for making the best out of it. In this age of aut...
A recipe for having fun and getting things done with the Raspberry Pi ...
Grokking Deep Learning teaches you to build deep learning neural networks from scratch! In his immersive style, deep learning expert Andrew Trask shows you the hidden science so you can uncover every ...