是否有 Python 的示例数据集?

Are there any example data sets for Python?(是否有 Python 的示例数据集?)
本文介绍了是否有 Python 的示例数据集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了快速测试、调试、创建可移植示例和基准测试,R 提供了大量数据集(在 Base R datasets 包中).R 提示符下的命令 library(help="datasets") 描述了近 100 个历史数据集,每个数据集都有相关的描述和元数据.

For quick testing, debugging, creating portable examples, and benchmarking, R has available to it a large number of data sets (in the Base R datasets package). The command library(help="datasets") at the R prompt describes nearly 100 historical datasets, each of which have associated descriptions and metadata.

Python 有这样的东西吗?

Is there anything like this for Python?

推荐答案

可以使用rpy2 包从 Python 访问所有 R 数据集.

You can use rpy2 package to access all R datasets from Python.

设置界面:

>>> from rpy2.robjects import r, pandas2ri
>>> def data(name): 
...    return pandas2ri.ri2py(r[name])

然后使用可用数据集的任何数据集名称调用 data()(就像在 R 中一样)

Then call data() with any dataset's name of the available datasets (just like in R)

>>> df = data('iris')
>>> df.describe()
       Sepal.Length  Sepal.Width  Petal.Length  Petal.Width
count    150.000000   150.000000    150.000000   150.000000
mean       5.843333     3.057333      3.758000     1.199333
std        0.828066     0.435866      1.765298     0.762238
min        4.300000     2.000000      1.000000     0.100000
25%        5.100000     2.800000      1.600000     0.300000
50%        5.800000     3.000000      4.350000     1.300000
75%        6.400000     3.300000      5.100000     1.800000
max        7.900000     4.400000      6.900000     2.500000

要查看可用数据集的列表以及每个数据集的描述:

To see a list of the available datasets with a description for each:

>>> print(r.data())

注意:rpy2 需要安装 R 并设置 R_HOME 变量和 pandas 也必须安装.

Note: rpy2 requires R installation with setting R_HOME variable, and pandas must be installed as well.

我刚刚创建了 PyDataset,这是一个简单的模块,可以让从 Python 加载数据集变得如此简单作为 R 的(并且它不需要 R 安装,只需要 pandas).

I just created PyDataset, which is a simple module to make loading a dataset from Python as easy as R's (and it does not require R installation, only pandas).

要开始使用它,请安装模块:

To start using it, install the module:

$ pip install pydataset

然后只需加载您想要的任何数据集(目前大约有 757 个数据集可用):

Then just load up any dataset you wish (currently around 757 datasets available):

from pydataset import data

titanic = data('titanic')

这篇关于是否有 Python 的示例数据集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)