我在GitHub上有以下网页,我希望将其内容导入python特别是jupyter笔记本
import pandas as pd
url = 'https://github.com/stedy/Machine-Learning-with-R-datasets/blob/master/groceries.csv'
file1=open(url,'r')
UnOrgan=file1.read()
但它不起作用
SError: [Errno 22] Invalid argument:
有人可以帮我这个吗?
答案 0 :(得分:2)
您无法将网址传递给open()。尝试使用请求库:
import requests
url = 'https://github.com/stedy/Machine-Learning-with-R-datasets/blob/master/groceries.csv'
response = requests.get(url)
print(response.text)
答案 1 :(得分:1)
输入您要导入的网页,然后单击Raw
从浏览器复制地址: “ https://raw.githubusercontent.com/stedy/Machine-Learning-with-R-datasets/master/groceries.csv”
#Use the address here:
url = 'https://raw.githubusercontent.com/stedy/Machine-Learning-with-R-datasets/master/groceries.csv'
#Name the resulting dataframe
dataDF = pd.read_csv(url)