首页 > 解决方案 > 如何在一个单元格中同时显示随机数据和数据集的描述性统计数据?(Jupyter 笔记本,熊猫)

问题描述

虹膜

嗨,有人可以帮我解决这个问题吗?我想在一个单元格中同时显示随机抽样的观察结果和描述性统计数据。但是,作为初学者,我只能展示其中一个。

这是我的代码:

import pandas as pd

iris = pd.read_csv('iris.csv')    # Import the csv data
iris = iris.drop('Id', axis = 1)    # Delete the 'Id' column
random = iris.sample(10)    # Use the sample method to get 10 random samples
random    # Show the 10 random samples
random.describe()    # Get the descriptive stats

感谢您的时间和关注!

标签: pythonpandasdataframejupyter-notebook

解决方案


它将垂直显示,这可以通过display(). 如果你想让它水平,请参考这个答案

display(random, random.describe())

    sepal_length    sepal_width     petal_length    petal_width     species
141     6.9     3.1     5.1     2.3     virginica
60  5.0     2.0     3.5     1.0     versicolor
65  6.7     3.1     4.4     1.4     versicolor
57  4.9     2.4     3.3     1.0     versicolor
14  5.8     4.0     1.2     0.2     setosa
58  6.6     2.9     4.6     1.3     versicolor
79  5.7     2.6     3.5     1.0     versicolor
102     7.1     3.0     5.9     2.1     virginica
82  5.8     2.7     3.9     1.2     versicolor
15  5.7     4.4     1.5     0.4     setosa
    sepal_length    sepal_width     petal_length    petal_width
count   10.000000   10.000000   10.00000    10.000000
mean    6.020000    3.020000    3.69000     1.190000
std     0.769993    0.714609    1.47079     0.652261
min     4.900000    2.000000    1.20000     0.200000
25%     5.700000    2.625000    3.35000     1.000000
50%     5.800000    2.950000    3.70000     1.100000
75%     6.675000    3.100000    4.55000     1.375000
max     7.100000    4.400000    5.90000     2.300000

在此处输入图像描述


推荐阅读