带有Pandas的Python-无法从URL读取CSV文件

时间:2018-12-02 00:10:49

标签: python-3.x pandas linear-regression

导入以下库后,我试图从here.

读取CSV文件。
    `import pandas as pd
     import numpy as np
     import matplotlib.pyplot as plt
     from sklearn.linear_model import LinearRegression
     from sklearn.metrics import r2_score
     import statsmodels.api as sm
     from pandas.core import datetools`

    `data = pd.read_csv("https://github.com/marcopeix/ISL-linear-` 
     regression/blob/master/data/Advertising.csv", sep='delimiter', 
     header=None,` `engine='python')`

请允许我解释一下为什么我得到HTML标签作为输出的原因。

`data.head(5)`

  ` 0
    0   <!DOCTYPE html>
    1   <html lang="en">
    2   <head>
    3   <meta charset="utf-8">
    4   <link rel="dns-prefetch" href="https://assets-...`

1 个答案:

答案 0 :(得分:2)

如果转到Github页面,则会在右端找到Raw,如下面的屏幕快照所示。点击原始文件并复制其网址。

enter image description here

以下是适合您的网址:

import pandas as pd
data = pd.read_csv("https://raw.githubusercontent.com/marcopeix/ISL-linear-regression/master/data/Advertising.csv")