1. 程式人生 > >用pandas讀取github的線上資料

用pandas讀取github的線上資料

用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函式進行轉換。