用pandas读取github在线数据。
import pandas as pd
url="https://raw.githubusercontent.com/hunkim/DeepLearningZeroToAll/master/data-03-diabetes.csv"
c=pd.read_csv(url,header=None)
import pandas as pd
import io
import requests
url="https://raw.githubusercontent.com/hunkim/DeepLearningZeroToAll/master/data-03-diabetes.csv"
s=requests.get(url).content
c=pd.read_csv(io.StringIO(s.decode('utf-8')),header=None)
pandas.read_csv
needs a file-like object as the first argument.
所以需要通过io.StringIO
函数进行转换。
注意要选择csv文件的raw URL。
如直接用:
“https://githubusercontent.com/hunkim/DeepLearningZeroToAll/master/data-03-diabetes.csv“,就会报错。
需转换为:
“https://raw.githubusercontent.com/hunkim/DeepLearningZeroToAll/master/data-03-diabetes.csv”