Sample datasets in Pandas

前端 未结 4 1282
醉酒成梦
醉酒成梦 2021-01-29 23:43

When using R it\'s handy to load \"practice\" datasets using

data(iris)

or

data(mtcars)

Is there something s

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-29 23:59

    Any publically available .csv file can be loaded into pandas extremely quickly using its URL. Here is an example using the iris dataset originally from the UCI archive.

    import pandas as pd
    
    file_name = "https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv"
    df = pd.read_csv(file_name)
    df.head()
    

    The output here being the .csv file header you just loaded from the given URL.

    >>> df.head()
       sepal_length  sepal_width  petal_length  petal_width species
    0           5.1          3.5           1.4          0.2  setosa
    1           4.9          3.0           1.4          0.2  setosa
    2           4.7          3.2           1.3          0.2  setosa
    3           4.6          3.1           1.5          0.2  setosa
    4           5.0          3.6           1.4          0.2  setosa
    

    A memorable short URL for the same is https://j​.mp/iriscsv. This short URL will work only if it's typed and not if it's copy-pasted.

提交回复
热议问题